Struct HttpBuilder

Source
pub struct HttpBuilder { /* private fields */ }
Expand description

A builder for the underlying Http client that performs requests to Discord’s HTTP API

If you do not need to use a proxy or do not need to disable the rate limiter, you can use Http::new instead.

§Example

Create an instance of Http with a proxy and rate limiter disabled

let http =
    HttpBuilder::new("token").proxy("http://127.0.0.1:3000").ratelimiter_disabled(true).build();

Implementations§

Source§

impl HttpBuilder

Source

pub fn new(token: impl AsRef<str>) -> Self

Construct a new builder to call methods on for the HTTP construction. The token will automatically be prefixed “Bot “ if not already.

Source

pub fn application_id(self, application_id: ApplicationId) -> Self

Sets the application_id to use interactions.

Source

pub fn token(self, token: impl AsRef<str>) -> Self

Sets a token for the bot. If the token is not prefixed “Bot “, this method will automatically do so.

Source

pub fn client(self, client: Client) -> Self

Sets the reqwest::Client. If one isn’t provided, a default one will be used.

Source

pub fn ratelimiter(self, ratelimiter: Ratelimiter) -> Self

Sets the ratelimiter to be used. If one isn’t provided, a default one will be used.

Source

pub fn ratelimiter_disabled(self, ratelimiter_disabled: bool) -> Self

Sets whether or not the ratelimiter is disabled. By default if this this not used, it is enabled. In most cases, this should be used in conjunction with Self::proxy.

Note: You should not disable the ratelimiter unless you have another form of rate limiting. Disabling the ratelimiter has the main purpose of delegating rate limiting to an API proxy via Self::proxy instead of the current process.

Source

pub fn proxy(self, proxy: impl Into<String>) -> Self

Sets the proxy that Discord HTTP API requests will be passed to. This is mainly intended for something like twilight-http-proxy where multiple processes can make API requests while sharing a single ratelimiter.

The proxy should be in the form of the protocol and hostname, e.g. http://127.0.0.1:3000 or http://myproxy.example

This will simply send HTTP API requests to the proxy instead of Discord API to allow the proxy to intercept, rate limit, and forward requests. This is different than a native proxy’s behavior where it will tunnel requests that use TLS via HTTP CONNECT method (e.g. using reqwest::Proxy).

Source

pub fn default_allowed_mentions( self, allowed_mentions: CreateAllowedMentions, ) -> Self

Sets the CreateAllowedMentions used by default for each request that would use it.

This only takes effect if you are calling through the model or builder methods, not directly calling Http methods, as Http is simply used as a convenient storage for these.

Source

pub fn build(self) -> Http

Use the given configuration to build the Http client.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T