twilight_http

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§

  • Markers denoting the type of response body.

Structs§

Enums§