Module response

Source
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§

BytesFuture
Future resolving to the bytes of a response body.
DeserializeBodyError
Failure when processing a response body.
HeaderIter
Iterator over the headers of a Response.
ModelFuture
Future resolving to a deserialized model.
Response
Response wrapper containing helper functions over the HTTP client’s response.
ResponseFuture
Future that will resolve to a Response.
StatusCode
Status code of a response.
TextFuture
Future resolving to the text of a response body.

Enums§

DeserializeBodyErrorType
Type of DeserializeBodyError that occurred.