pub struct Request<'a> { /* private fields */ }Expand description
A request to send with Rest::request.
discord.js counterpart: RequestData (@discordjs/rest).
§Examples
use djs_model::{id::ChannelId, rest::CreateMessage};
use djs_rest::{Request, Route};
let request = Request::new(Route::CreateMessage { channel_id: ChannelId::new(1) })
.json(&CreateMessage::from("hi"))
.unwrap();
assert_eq!(request.route(), Route::CreateMessage { channel_id: ChannelId::new(1) });Implementations§
Source§impl<'a> Request<'a>
impl<'a> Request<'a>
Sourcepub const fn new(route: Route<'a>) -> Self
pub const fn new(route: Route<'a>) -> Self
Creates a request without a body.
discord.js counterpart: RequestData (@discordjs/rest).
Sourcepub const fn reason(self, reason: Option<&'a str>) -> Self
pub const fn reason(self, reason: Option<&'a str>) -> Self
Sets the reason shown in the guild’s
audit log for the action
(the X-Audit-Log-Reason header, sent percent-encoded, so any text is allowed). Only
endpoints whose docs mention the header use it; None sends no reason.
discord.js counterpart: the reason option of REST#request.
§Examples
use djs_model::id::{ChannelId, MessageId};
use djs_rest::{Request, Route};
let route = Route::PinMessage {
channel_id: ChannelId::new(1),
message_id: MessageId::new(2),
};
let request = Request::new(route).reason(Some("Important"));
assert_eq!(request.audit_log_reason(), Some("Important"));Sourcepub const fn files(self, files: &'a [FileUpload]) -> Self
pub const fn files(self, files: &'a [FileUpload]) -> Self
Uploads files with the request (D-087). The request is then sent as
multipart/form-data: file n as the part files[n] (with its content type, guessed
from its name if not given, D-095) and the JSON body as payload_json. The file data is
not copied, not even for retries.
The JSON body must describe the files in its attachments; the body structs of
djs_model::rest do that automatically for their own files field (D-094), which the
typed Rest methods pass here.
discord.js counterpart: the files option of REST#request.
§Examples
use djs_model::{
id::ChannelId,
rest::{CreateMessage, FileUpload},
};
use djs_rest::{Request, Route};
let body = CreateMessage::from("The log:").file(FileUpload::new("log.txt", "everything is fine\n"));
let request = Request::new(Route::CreateMessage { channel_id: ChannelId::new(1) })
.json(&body)
.unwrap()
.files(&body.files);
assert_eq!(request.uploads().len(), 1);Sourcepub const fn uploads(&self) -> &'a [FileUpload]
pub const fn uploads(&self) -> &'a [FileUpload]
Returns the files set with files.
discord.js counterpart: the files of RequestData (@discordjs/rest).
Sourcepub const fn audit_log_reason(&self) -> Option<&'a str>
pub const fn audit_log_reason(&self) -> Option<&'a str>
Returns the audit log reason set with reason.
discord.js counterpart: the reason of RequestData (@discordjs/rest).