[][src]Module ttv_rs::client

This is supported on crate feature client only.

Different clients you can use with this crate to call endpoints.

This enables you to use your own http client/implementation. For example, say you have a http client that has a "client" named foo::Client.

That client has a function call which looks something like this

fn call(&self, req: http::Request<Vec<u8>>) -> futures::future::BoxFuture<'static, Result<http::Response<Vec<u8>>, ClientError>> {
    ...
}

To use that for requests we do the following.

use twitch_api2::client::{BoxedFuture, Req, Response};
impl<'a> twitch_api2::HttpClient<'a> for foo::Client {
    type Error = foo::ClientError;

    fn req(&'a self, request: Req) -> BoxedFuture<'static, Result<Response, Self::Error>> {
        let fut = self.call(request);
        Box::pin(async {fut.await})
    }
}

We can then use it like usual.

pub struct MyStruct {
   twitch: TwitchClient<'static, foo::Client>,
   token: twitch_oauth2::AppAccessToken,
}

If your client is from a remote crate, you can use the newtype pattern

Of course, sometimes the clients use different types for their responses and requests. but simply translate them into [http] types and it will work.

See the source of this module for the implementation of Client for surf and reqwest if you need inspiration.

Structs

DummyHttpClient

A client that will never work, used to trick documentation tests

Enums

SurfError

Possible errors from Client::req() when using [surf::Client]

Traits

Client

A client that can do requests

Type Definitions

BoxedFuture

A boxed future, mimics futures::future::BoxFuture

Req

The request type we're expecting with body.

Response

The response type we're expecting with body