pub struct Client { /* private fields */ }
Expand description

Client for communicating with APIs through HTTP/HTTPS.

When making a HTTP request or starting a websocket connection with this client, a handler that implements RequestHandler is required.

Implementations§

Constructs a new Client.

Makes an HTTP request with the given RequestHandler and returns the response.

It is recommended to use methods like get() because this method takes many type parameters and parameters.

The request is passed to handler before being sent, and the response is passed to handler before being returned. Note, that as stated in the docs for RequestBuilder::query(), parameter query only accepts a sequence of key-value pairs.

Examples found in repository?
src/http.rs (line 90)
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
    pub async fn get<Q, H>(&self, url: &str, query: Option<&Q>, handler: &H) -> Result<H::Successful, RequestError<H::BuildError, H::Unsuccessful>>
    where
        Q: Serialize + ?Sized,
        H: RequestHandler<()>,
    {
        self.request::<Q, (), H>(Method::GET, url, query, None, handler).await
    }

    /// Makes an GET request with the given [RequestHandler], without queries.
    ///
    /// This method just calls [request()][Self::request()]. It requires less typing for type parameters and parameters.
    /// This method requires that `handler` can handle a request with a body of type `()`. The actual body passed will be `None`.
    ///
    /// For more information, see [request()][Self::request()].
    #[inline(always)]
    pub async fn get_no_query<H>(&self, url: &str, handler: &H) -> Result<H::Successful, RequestError<H::BuildError, H::Unsuccessful>>
    where
        H: RequestHandler<()>,
    {
        self.request::<&[(&str, &str)], (), H>(Method::GET, url, None, None, handler).await
    }

    /// Makes an POST request with the given [RequestHandler].
    ///
    /// This method just calls [request()][Self::request()]. It requires less typing for type parameters and parameters.
    ///
    /// For more information, see [request()][Self::request()].
    #[inline(always)]
    pub async fn post<B, H>(&self, url: &str, body: Option<B>, handler: &H) -> Result<H::Successful, RequestError<H::BuildError, H::Unsuccessful>>
    where
        H: RequestHandler<B>,
    {
        self.request::<(), B, H>(Method::POST, url, None, body, handler).await
    }

    /// Makes an POST request with the given [RequestHandler], without a body.
    ///
    /// This method just calls [request()][Self::request()]. It requires less typing for type parameters and parameters.
    /// This method requires that `handler` can handle a request with a body of type `()`. The actual body passed will be `None`.
    ///
    /// For more information, see [request()][Self::request()].
    #[inline(always)]
    pub async fn post_no_body<H>(&self, url: &str, handler: &H) -> Result<H::Successful, RequestError<H::BuildError, H::Unsuccessful>>
    where
        H: RequestHandler<()>,
    {
        self.request::<(), (), H>(Method::POST, url, None, None, handler).await
    }

    /// Makes an PUT request with the given [RequestHandler].
    ///
    /// This method just calls [request()][Self::request()]. It requires less typing for type parameters and parameters.
    ///
    /// For more information, see [request()][Self::request()].
    #[inline(always)]
    pub async fn put<B, H>(&self, url: &str, body: Option<B>, handler: &H) -> Result<H::Successful, RequestError<H::BuildError, H::Unsuccessful>>
    where
        H: RequestHandler<B>,
    {
        self.request::<(), B, H>(Method::PUT, url, None, body, handler).await
    }

    /// Makes an PUT request with the given [RequestHandler], without a body.
    ///
    /// This method just calls [request()][Self::request()]. It requires less typing for type parameters and parameters.
    /// This method requires that `handler` can handle a request with a body of type `()`. The actual body passed will be `None`.
    ///
    /// For more information, see [request()][Self::request()].
    #[inline(always)]
    pub async fn put_no_body<H>(&self, url: &str, handler: &H) -> Result<H::Successful, RequestError<H::BuildError, H::Unsuccessful>>
    where
        H: RequestHandler<()>,
    {
        self.request::<(), (), H>(Method::PUT, url, None, None, handler).await
    }

    /// Makes an DELETE request with the given [RequestHandler].
    ///
    /// This method just calls [request()][Self::request()]. It requires less typing for type parameters and parameters.
    /// This method requires that `handler` can handle a request with a body of type `()`. The actual body passed will be `None`.
    ///
    /// For more information, see [request()][Self::request()].
    #[inline(always)]
    pub async fn delete<Q, H>(&self, url: &str, query: Option<&Q>, handler: &H) -> Result<H::Successful, RequestError<H::BuildError, H::Unsuccessful>>
    where
        Q: Serialize + ?Sized,
        H: RequestHandler<()>,
    {
        self.request::<Q, (), H>(Method::DELETE, url, query, None, handler).await
    }

    /// Makes an DELETE request with the given [RequestHandler], without queries.
    ///
    /// This method just calls [request()][Self::request()]. It requires less typing for type parameters and parameters.
    /// This method requires that `handler` can handle a request with a body of type `()`. The actual body passed will be `None`.
    ///
    /// For more information, see [request()][Self::request()].
    #[inline(always)]
    pub async fn delete_no_query<H>(&self, url: &str, handler: &H) -> Result<H::Successful, RequestError<H::BuildError, H::Unsuccessful>>
    where
        H: RequestHandler<()>,
    {
        self.request::<&[(&str, &str)], (), H>(Method::DELETE, url, None, None, handler).await
    }

Makes an GET request with the given RequestHandler.

This method just calls request(). It requires less typing for type parameters and parameters. This method requires that handler can handle a request with a body of type (). The actual body passed will be None.

For more information, see request().

Makes an GET request with the given RequestHandler, without queries.

This method just calls request(). It requires less typing for type parameters and parameters. This method requires that handler can handle a request with a body of type (). The actual body passed will be None.

For more information, see request().

Makes an POST request with the given RequestHandler.

This method just calls request(). It requires less typing for type parameters and parameters.

For more information, see request().

Makes an POST request with the given RequestHandler, without a body.

This method just calls request(). It requires less typing for type parameters and parameters. This method requires that handler can handle a request with a body of type (). The actual body passed will be None.

For more information, see request().

Makes an PUT request with the given RequestHandler.

This method just calls request(). It requires less typing for type parameters and parameters.

For more information, see request().

Makes an PUT request with the given RequestHandler, without a body.

This method just calls request(). It requires less typing for type parameters and parameters. This method requires that handler can handle a request with a body of type (). The actual body passed will be None.

For more information, see request().

Makes an DELETE request with the given RequestHandler.

This method just calls request(). It requires less typing for type parameters and parameters. This method requires that handler can handle a request with a body of type (). The actual body passed will be None.

For more information, see request().

Makes an DELETE request with the given RequestHandler, without queries.

This method just calls request(). It requires less typing for type parameters and parameters. This method requires that handler can handle a request with a body of type (). The actual body passed will be None.

For more information, see request().

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more