pub struct RequestBuilder(_);
Expand description

Builder to create a customized request.

Examples

Create a request to create a message with a content of “test” in a channel with an ID of 1:

use twilight_http::{request::Request, routing::Route};

let body = br#"{
    "content": "test"
}"#
.to_vec();

let request = Request::builder(&Route::CreateMessage { channel_id: 1 })
    .body(body)
    .build();

Implementations§

Create a new request builder.

Create a request with raw information about the method, ratelimiting path, and URL path and query.

The path and query should not include the leading slash as that is prefixed by the client. In the URL https://discord.com/api/vX/channels/123/pins the “path and query” is considered to be channels/123/pins.

Examples

Create a request from a method and the URL path and query channels/123/pins:

use std::str::FromStr;
use twilight_http::{
    request::{Method, RequestBuilder},
    routing::Path,
};

let method = Method::Post;
let path_and_query = "channels/123/pins".to_owned();
let ratelimit_path = Path::from_str(&path_and_query)?;

let _request = RequestBuilder::raw(method, ratelimit_path, path_and_query).build();

Consume the builder, returning the built request.

Set the contents of the body.

Set the multipart form.

Set the headers to add.

Set the body, to be serialized as JSON.

Errors

Returns an ErrorType::Json error type if the value could not be serialized as JSON.

Whether to use the client’s authorization token in the request, if one is set.

This is primarily useful for executing webhooks.

Trait Implementations§

Formats the value using the given formatter. 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.

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