Expand description
Response utility type and related types.
The heart of the response module is the Response itself: it’s a wrapper
over the underlying HTTP client’s response, containing helper methods for
things like getting the raw bytes of the response body, getting
an iterator of the response headers, or
deserializing the body into a model.
The ResponseFuture is a type implementing Future that resolves to a
Response when polled or .awaited to completion.
§Examples
Get a user by ID, check if the request was successful, and if so deserialize
the response body via Response::model and print the user’s
name:
use std::env;
use twilight_http::Client;
let client = Client::new(env::var("DISCORD_TOKEN")?);
let response = client.user(user_id).await?;
if !response.status().is_success() {
println!("failed to get user");
return Ok(());
}
// Twilight already knows to deserialize it into a
// `twilight_model::user::User`.
let user = response.model().await?;
println!("user's name: {}:{}", user.name, user.discriminator);Modules§
- marker
- Markers denoting the type of response body.
Structs§
- Bytes
Future - Future resolving to the bytes of a response body.
- Deserialize
Body Error - Failure when processing a response body.
- Header
Iter - Iterator over the headers of a
Response. - Model
Future - Future resolving to a deserialized model.
- Response
- Response wrapper containing helper functions over the HTTP client’s response.
- Response
Future - Future that will resolve to a
Response. - Status
Code - Status code of a response.
- Text
Future - Future resolving to the text of a response body.
Enums§
- Deserialize
Body Error Type - Type of
DeserializeBodyErrorthat occurred.