Available on crate feature
client
only.Expand description
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<Bytes>) -> futures::future::BoxFuture<'static, Result<http::Response<Bytes>, ClientError>> {
...
}
To use that for requests we do the following.
use twitch_api::client::{BoxedFuture, Request, Response};
mod foo {
use twitch_api::client::{BoxedFuture, Bytes, Response};
pub struct Client;
impl Client {
pub fn call(
&self,
req: http::Request<Bytes>,
) -> futures::future::BoxFuture<
'static,
Result<http::Response<Bytes>, ClientError>,
> {
unimplemented!()
}
}
pub type ClientError = std::io::Error;
}
impl twitch_api::HttpClient for foo::Client {
type Error = foo::ClientError;
fn req(
&self,
request: Request,
) -> BoxedFuture<'_, Result<Response, Self::Error>> {
Box::pin(async move { self.call(request).await })
}
}
// And for full usage
use twitch_api::TwitchClient;
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§
- Bytes
- A cheaply cloneable and sliceable chunk of contiguous memory.
- Dummy
Http Client - A client that will never work, used to trick documentation tests
- Tower
Service tower
- A wrapped tower service
Enums§
- Compat
Error - A compability shim for ensuring an error can represent
hyper::Error
- Reqwest
Client Default Error reqwest
- Possible errors from
ClientDefault::default_client_with_name
for reqwest - Surf
Error surf
- Possible errors from
Client::req()
when using the surf client - Tower
Error tower
- Errors that can occur when using a
TowerService
- Ureq
Error ureq
- Possible errors from
Client::req()
when using the ureq client
Statics§
- TWITCH_
API_ USER_ AGENT - The User-Agent
product
of this crate.
Traits§
- Client
- A client that can do requests
- Client
Default - A specific client default for setting some sane defaults for API calls and oauth2 usage
- Response
Ext - Extension trait for
Response
Functions§
- user_
agent - Gives the User-Agent header value for a client annotated with an added
twitch_api
product
Type Aliases§
- Boxed
Future - A boxed future, mimics
futures::future::BoxFuture
- Request
- The request type we’re expecting with body.
- Response
- The response type we’re expecting with body