Struct twilight_http::request::RequestBuilder [−][src]
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 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();
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
Auto Trait Implementations
impl RefUnwindSafe for RequestBuilder
impl Send for RequestBuilder
impl Sync for RequestBuilder
impl Unpin for RequestBuilder
impl UnwindSafe for RequestBuilder