Struct simplist::HttpSyncClient [] [src]

pub struct HttpSyncClient { /* fields omitted */ }

a synchronous, blocking http client.

a class for sending http requests and receiving http responses from a resource identified by a uri. this class uses tokio behind the scenes, but exposes a blocking, synchronous api.

all examples here assume that you have an existing tokio reactor you can use. if you not already have a tokio core, a complete example demonstrating the initialization and usage of tokio together with this http client is available at https://github.com/hinaria/simplist/blob/master/examples/basic-sync.rs.

methods

this struct provides two sets of operations for performing http operations: one for returning the response as a Vec<u8>, and another for returning the response as a String.

finally, there is a separate method, fn request(...) that takes a HttpRequest and allows you to manually set the http method, as well as set http headers.

rustdoc currently generates some pretty unreadable documentation for this struct, so we'll summarize the available methods here.

methods returning a Vec<u8>:

.
    fn options(url, Option<body>) -> Result<Vec<u8>, HttpError>;
    fn get    (url)               -> Result<Vec<u8>, HttpError>;
    fn post   (url, Option<body>) -> Result<Vec<u8>, HttpError>;
    fn put    (url, Option<body>) -> Result<Vec<u8>, HttpError>;
    fn delete (url)               -> Result<Vec<u8>, HttpError>;
    fn head   (url)               -> Result<Vec<u8>, HttpError>;
    fn trace  (url)               -> Result<Vec<u8>, HttpError>;
    fn connect(url)               -> Result<Vec<u8>, HttpError>;
    fn patch  (url, Option<body>) -> Result<Vec<u8>, HttpError>;

methods returning a String<u8>:

.
    fn options_string(url, Option<body>) -> Result<String, HttpError>;
    fn get_string    (url)               -> Result<String, HttpError>;
    fn post_string   (url, Option<body>) -> Result<String, HttpError>;
    fn put_string    (url, Option<body>) -> Result<String, HttpError>;
    fn delete_string (url)               -> Result<String, HttpError>;
    fn head_string   (url)               -> Result<String, HttpError>;
    fn trace_string  (url)               -> Result<String, HttpError>;
    fn connect_string(url)               -> Result<String, HttpError>;
    fn patch_string  (url, Option<body>) -> Result<String, HttpError>;

examples

use simplist::HttpSyncClient;

let http = HttpSyncClient::new(handle);
let html = http.get_string("https://hinaria.com")?;

println!("{:?}", html);
// => "<!doctype html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"utf-8\"> ..."

Methods

impl HttpSyncClient
[src]

[src]

creates a new http client.

this method is very cheap, and does not perform any kind of initialization.

examples

use simplist::HttpSyncClient;

let http = HttpSyncClient::new(handle);

[src]

sends a http request.

examples

use simplist::HttpClient;
use simplist::HttpMethod;

let http      = HttpClient::new(handle);
let url       = "https://hinaria.com".parse()?;
let operation = HttpRequest::with(url, HttpMethod::Get);
let response  = http.request(operation)?;

assert_eq!(response.status(), StatusCode::Ok);

impl HttpSyncClient
[src]

[src]

sends an asynchronous http request, returning the response as a Vec<u8>.

the request body can be any type that is convertible to a HttpContent. refer to HttpContent to see a list of types that can be used.

examples

use simplist::HttpSyncClient;

let http = HttpSyncClient::new(handle);
let body = Some("{ id: 1234 }");

assert_eq!(
    &http.post("https://hinaria.com/users/@me/database", body)?,
    &[60, 33, 68, 79, 67, 84, 89, 80, 69, 32, 104, 116, ...]);

[src]

sends an asynchronous http request, returning the response as a String.

the request body can be any type that is convertible to a HttpContent. refer to HttpContent to see a list of types that can be used.

examples

use simplist::HttpSyncClient;

let http = HttpSyncClient::new(handle);
let body = Some("{ id: 1234 }");

assert_eq!(
    &http.post_string("https://hinaria.com/users/@me/database", body)?,
    "<!doctype html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"utf-8\"> ...");

impl HttpSyncClient
[src]

[src]

sends an http request, returning the response as a Vec<u8>.

examples

use simplist::HttpSyncClient;

let http = HttpSyncClient::new(handle);

assert_eq!(
    &http.get("https://hinaria.com")?,
    &[60, 33, 68, 79, 67, 84, 89, 80, 69, 32, 104, 116, ...]);

[src]

sends an asynchronous http request, returning the response as a String.

examples

use simplist::HttpSyncClient;

let http = HttpSyncClient::new(handle);

assert_eq!(
    http.get_string("https://hinaria.com")?,
    "<!doctype html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"utf-8\"> ...");

impl HttpSyncClient
[src]

[src]

sends an asynchronous http request, returning the response as a Vec<u8>.

the request body can be any type that is convertible to a HttpContent. refer to HttpContent to see a list of types that can be used.

examples

use simplist::HttpSyncClient;

let http = HttpSyncClient::new(handle);
let body = Some("{ id: 1234 }");

assert_eq!(
    &http.post("https://hinaria.com/users/@me/database", body)?,
    &[60, 33, 68, 79, 67, 84, 89, 80, 69, 32, 104, 116, ...]);

[src]

sends an asynchronous http request, returning the response as a String.

the request body can be any type that is convertible to a HttpContent. refer to HttpContent to see a list of types that can be used.

examples

use simplist::HttpSyncClient;

let http = HttpSyncClient::new(handle);
let body = Some("{ id: 1234 }");

assert_eq!(
    &http.post_string("https://hinaria.com/users/@me/database", body)?,
    "<!doctype html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"utf-8\"> ...");

impl HttpSyncClient
[src]

[src]

sends an asynchronous http request, returning the response as a Vec<u8>.

the request body can be any type that is convertible to a HttpContent. refer to HttpContent to see a list of types that can be used.

examples

use simplist::HttpSyncClient;

let http = HttpSyncClient::new(handle);
let body = Some("{ id: 1234 }");

assert_eq!(
    &http.post("https://hinaria.com/users/@me/database", body)?,
    &[60, 33, 68, 79, 67, 84, 89, 80, 69, 32, 104, 116, ...]);

[src]

sends an asynchronous http request, returning the response as a String.

the request body can be any type that is convertible to a HttpContent. refer to HttpContent to see a list of types that can be used.

examples

use simplist::HttpSyncClient;

let http = HttpSyncClient::new(handle);
let body = Some("{ id: 1234 }");

assert_eq!(
    &http.post_string("https://hinaria.com/users/@me/database", body)?,
    "<!doctype html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"utf-8\"> ...");

impl HttpSyncClient
[src]

[src]

sends an http request, returning the response as a Vec<u8>.

examples

use simplist::HttpSyncClient;

let http = HttpSyncClient::new(handle);

assert_eq!(
    &http.get("https://hinaria.com")?,
    &[60, 33, 68, 79, 67, 84, 89, 80, 69, 32, 104, 116, ...]);

[src]

sends an asynchronous http request, returning the response as a String.

examples

use simplist::HttpSyncClient;

let http = HttpSyncClient::new(handle);

assert_eq!(
    http.get_string("https://hinaria.com")?,
    "<!doctype html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"utf-8\"> ...");

impl HttpSyncClient
[src]

[src]

sends an http request, returning the response as a Vec<u8>.

examples

use simplist::HttpSyncClient;

let http = HttpSyncClient::new(handle);

assert_eq!(
    &http.get("https://hinaria.com")?,
    &[60, 33, 68, 79, 67, 84, 89, 80, 69, 32, 104, 116, ...]);

[src]

sends an asynchronous http request, returning the response as a String.

examples

use simplist::HttpSyncClient;

let http = HttpSyncClient::new(handle);

assert_eq!(
    http.get_string("https://hinaria.com")?,
    "<!doctype html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"utf-8\"> ...");

impl HttpSyncClient
[src]

[src]

sends an http request, returning the response as a Vec<u8>.

examples

use simplist::HttpSyncClient;

let http = HttpSyncClient::new(handle);

assert_eq!(
    &http.get("https://hinaria.com")?,
    &[60, 33, 68, 79, 67, 84, 89, 80, 69, 32, 104, 116, ...]);

[src]

sends an asynchronous http request, returning the response as a String.

examples

use simplist::HttpSyncClient;

let http = HttpSyncClient::new(handle);

assert_eq!(
    http.get_string("https://hinaria.com")?,
    "<!doctype html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"utf-8\"> ...");

impl HttpSyncClient
[src]

[src]

sends an http request, returning the response as a Vec<u8>.

examples

use simplist::HttpSyncClient;

let http = HttpSyncClient::new(handle);

assert_eq!(
    &http.get("https://hinaria.com")?,
    &[60, 33, 68, 79, 67, 84, 89, 80, 69, 32, 104, 116, ...]);

[src]

sends an asynchronous http request, returning the response as a String.

examples

use simplist::HttpSyncClient;

let http = HttpSyncClient::new(handle);

assert_eq!(
    http.get_string("https://hinaria.com")?,
    "<!doctype html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"utf-8\"> ...");

impl HttpSyncClient
[src]

[src]

sends an asynchronous http request, returning the response as a Vec<u8>.

the request body can be any type that is convertible to a HttpContent. refer to HttpContent to see a list of types that can be used.

examples

use simplist::HttpSyncClient;

let http = HttpSyncClient::new(handle);
let body = Some("{ id: 1234 }");

assert_eq!(
    &http.post("https://hinaria.com/users/@me/database", body)?,
    &[60, 33, 68, 79, 67, 84, 89, 80, 69, 32, 104, 116, ...]);

[src]

sends an asynchronous http request, returning the response as a String.

the request body can be any type that is convertible to a HttpContent. refer to HttpContent to see a list of types that can be used.

examples

use simplist::HttpSyncClient;

let http = HttpSyncClient::new(handle);
let body = Some("{ id: 1234 }");

assert_eq!(
    &http.post_string("https://hinaria.com/users/@me/database", body)?,
    "<!doctype html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"utf-8\"> ...");

Trait Implementations

impl Clone for HttpSyncClient
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Debug for HttpSyncClient
[src]

[src]

Formats the value using the given formatter.