pub struct RequestBuilder(/* private fields */);
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§
source§impl RequestBuilder
impl RequestBuilder
sourcepub const fn raw(
method: Method,
ratelimit_path: Path,
path_and_query: String,
) -> Self
pub const fn raw( method: Method, ratelimit_path: Path, path_and_query: String, ) -> Self
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();
sourcepub fn build(self) -> Result<Request, Error>
pub fn build(self) -> Result<Request, Error>
Consume the builder, returning the built request.
§Errors
Returns an ErrorType::Json
error type JSON input could not be
serialized.
sourcepub fn headers(
self,
iter: impl Iterator<Item = (HeaderName, HeaderValue)>,
) -> Self
pub fn headers( self, iter: impl Iterator<Item = (HeaderName, HeaderValue)>, ) -> Self
Set the headers to add.
Whether to use the client’s authorization token in the request, if one is set.
This is primarily useful for executing webhooks.