[][src]Struct roy::Client

pub struct Client {
    pub base_url: String,
    // some fields omitted
}

The HTTP client

Fields

base_url: String

API base URL

Implementations

impl Client[src]

pub fn new(base_url: String) -> Client[src]

Create a new instance of a Client

Usage:

use roy::Client;

let c = Client::new("https://httpbin.org".to_string());
assert_eq!(c.base_url, "https://httpbin.org");

pub fn new_auth(base_url: String, auth_token: &'static str) -> Client[src]

Create a new instance of an authenticated Client

Usage:

use roy::Client;
use tokio_test::block_on;

let c = Client::new_auth("https://httpbin.org".to_string(), "");
assert_eq!(block_on(c.get("/bearer", false)).is_some(), true);

pub async fn post<T: Serialize + Debug, '_, '_>(
    &'_ self,
    endpoint: &'_ str,
    data: T
) -> Option<Response>
[src]

Generic function to POST data to an endpoint

Usage:

use roy::Client;
use tokio_test::block_on;

let c = Client::new("https://httpbin.org".to_string());
assert_eq!(block_on(c.post("/post", "{data}")).is_some(), true);

pub async fn delete<'_, '_>(&'_ self, endpoint: &'_ str) -> Option<Response>[src]

Generic function to DELETE to an endpoint

Usage:

use roy::Client;
use tokio_test::block_on;

let c = Client::new("https://httpbin.org".to_string());
assert_eq!(block_on(c.delete("/delete")).is_some(), true);

pub async fn patch<T: Serialize + Debug, '_, '_>(
    &'_ self,
    endpoint: &'_ str,
    data: T
) -> Option<Response>
[src]

Generic function to PATCH data to an endpoint

Usage:

use roy::Client;
use tokio_test::block_on;

let c = Client::new("https://httpbin.org".to_string());
assert_eq!(block_on(c.patch("/patch", "{data}")).is_some(), true);

pub async fn put<T: Serialize + Debug, '_, '_>(
    &'_ self,
    endpoint: &'_ str,
    data: T
) -> Option<Response>
[src]

Generic function to PUT data to an endpoint

Usage:

use roy::Client;
use tokio_test::block_on;

let c = Client::new("https://httpbin.org".to_string());
assert_eq!(block_on(c.put("/put", "{data}")).is_some(), true);

pub async fn get<'_, '_>(
    &'_ self,
    endpoint: &'_ str,
    single: bool
) -> Option<Response>
[src]

Generic function to send a GET request to an endpoint

Usage:

use roy::Client;
use tokio_test::block_on;

let c = Client::new("https://httpbin.org".to_string());
assert_eq!(block_on(c.get("/get", false)).is_some(), true);

Auto Trait Implementations

impl !RefUnwindSafe for Client

impl Send for Client

impl Sync for Client

impl Unpin for Client

impl !UnwindSafe for Client

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.