Request

Trait Request 

Source
pub trait Request {
    type Headers: Headers;
    type Parameters: Parameters;
    type Body: Body;
    type Response: Response + 'static;
    type ErrorCodes: ErrorCodes + 'static;

    const ENDPOINT: &'static str;
    const METHOD: Method;

    // Required methods
    fn builder() -> Self;
    fn headers(&self) -> &Self::Headers;
    fn parameters(&self) -> &Self::Parameters;
    fn body(&self) -> &Self::Body;
    fn ready(&self) -> Result<(), RequestError<Self::ErrorCodes>>;

    // Provided method
    fn make_request<'life0, 'async_trait, C>(
        &'life0 self,
        client: C,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Response, RequestError<Self::ErrorCodes>>> + Send + 'async_trait>>
       where C: Borrow<Client> + Send + 'async_trait,
             Self: Sync + 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

Represents a request that can be made to the twitch api

Required Associated Constants§

Source

const ENDPOINT: &'static str

Endpoint where the request is made

Source

const METHOD: Method

The method that this request will use

Required Associated Types§

Source

type Headers: Headers

The type that represents the headers sent with this request

Source

type Parameters: Parameters

The type that represents the query parameters sent with this request

Source

type Body: Body

The type that represents the body of this request

Source

type Response: Response + 'static

The type returned by a sucessful request, must be DeserializeOwned and have at least a static lifetime (owned).

Source

type ErrorCodes: ErrorCodes + 'static

The type that encapsulates the error codes that this endpoint can return, must have at least a static lifetime (owned).

Required Methods§

Source

fn builder() -> Self

Get a builder for this method

Source

fn headers(&self) -> &Self::Headers

Get the Headers struct for this Request

Will only be called when Self::ready returns Ok(()) and may not fail in that case

Source

fn parameters(&self) -> &Self::Parameters

Get the Parameters struct for this Request

Will only be called when Self::ready returns Ok(()) and may not fail in that case

Source

fn body(&self) -> &Self::Body

Get the Body struct for this Request

Will only be called when Self::ready returns Ok(()) and may not fail in that case

Source

fn ready(&self) -> Result<(), RequestError<Self::ErrorCodes>>

Must return Ok(()) if and only if this request is ready to have Self::make_request called on it.

Should return RequestError::MalformedRequest with a message in the case that the request is not ready to be sent.

Called by Self::make_request, error is propogated.

Provided Methods§

Source

fn make_request<'life0, 'async_trait, C>( &'life0 self, client: C, ) -> Pin<Box<dyn Future<Output = Result<Self::Response, RequestError<Self::ErrorCodes>>> + Send + 'async_trait>>
where C: Borrow<Client> + Send + 'async_trait, Self: Sync + 'async_trait, 'life0: 'async_trait,

Make the request represented by this object. Only makes request if Self::ready returns Ok(()).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Request for ClientAuthRequest

Source§

const ENDPOINT: &'static str = "https://id.twitch.tv/oauth2/token"

Source§

const METHOD: Method = reqwest::Method::POST

Source§

type Headers = ()

Source§

type Parameters = ClientAuthRequestParams

Source§

type Body = ()

Source§

type Response = ClientAuthResponse

Source§

type ErrorCodes = CommonResponseCodes

Source§

impl<A> Request for GetChannelInformationRequest<A>
where A: AuthToken + Sync,

Source§

const ENDPOINT: &'static str = "https://api.twitch.tv/helix/channels"

Source§

const METHOD: Method = reqwest::Method::GET

Source§

type Headers = A

Source§

type Parameters = GetChannelInformationRequest<A>

Source§

type Body = ()

Source§

type Response = GetChannelInformationResponse

Source§

type ErrorCodes = CommonResponseCodes

Source§

impl<A> Request for GetClipsRequest<A>
where A: AuthToken + Sync,

Source§

const ENDPOINT: &'static str = "https://api.twitch.tv/helix/clips"

Source§

const METHOD: Method = reqwest::Method::GET

Source§

type Headers = A

Source§

type Parameters = GetClipsRequest<A>

Source§

type Body = ()

Source§

type Response = GetClipsResponse

Source§

type ErrorCodes = CommonResponseCodes

Source§

impl<A> Request for GetUsersRequest<A>
where A: AuthToken + Send,

Source§

const ENDPOINT: &'static str = "https://api.twitch.tv/helix/users"

Source§

const METHOD: Method = reqwest::Method::GET

Source§

type Headers = A

Source§

type Parameters = GetUsersRequest<A>

Source§

type Body = ()

Source§

type Response = GetUsersResponse

Source§

type ErrorCodes = CommonResponseCodes