Skip to main content
Rest is an asynchronous HTTP client built on top of reqwest. Used directly via client.rest or through struct methods (guild.fetch_roles, channel.send, etc.). Rest is based on Arc - cloning is cheap, pass it into closures via .clone().

RestOptions

Passed into Rest::new(options) or configured via ClientOptions.rest.

Rest

Rest::new

Creates a REST client. The token is not set - call set_token before the first request. When used via Client, the token is set automatically during login.

set_token

Sets the authorization token. If the string does not start with "Bot " or "Bearer " - the prefix "Bot " is added automatically.

Request Methods

All methods take a route relative to api_url (e.g. /channels/123/messages) and return Result<T, RestError>.

get

Executes a GET request. Deserializes the response into T.

post

Executes a POST request with an optional JSON body.

patch

Executes a PATCH request with an optional JSON body.

put

Executes a PUT request with an optional JSON body.

put_empty

Executes a PUT request without a body and expects no content in the response. Used for operations like assigning a role (PUT /guilds/{id}/members/{user_id}/roles/{role_id}).

delete_route

Executes a DELETE request. Returns no response body.

post_multipart

Executes a POST request with multipart/form-data. Used for sending files. The Content-Type header is set automatically with the boundary.

Routes

Routes is a set of static methods for building API routes. All methods return String or &'static str.

Channels

Guilds

Users

Other

The Routes::channel_message_reaction method automatically URL-encodes the emoji parameter. Pass the emoji as-is: a Unicode character ("👍") or "name:id" for custom ones.

Rate Limiting

RateLimitManager manages rate limits automatically. No manual intervention is required.

Behavior

  • Before each request, the global rate limit and per-route bucket are checked.
  • If remaining == 0 for a bucket - the request waits until reset_at.
  • When a 429 response is received, the client waits retry_after seconds and retries the request.
  • The number of retries is limited by RestOptions.max_retries (default: 3).
  • After all attempts are exhausted, RestError::RateLimit(RateLimitError) is returned.

Bucket Keys

Routes are normalized before being stored in a bucket: numeric IDs are replaced with :id. This allows grouping requests to the same resource into one bucket. Normalization example:

Global Rate Limit

If the response contains the header x-ratelimit-global: true - a global lock is set for the duration of retry_after. All subsequent requests wait for the lock to be released.

Error Handling

RestError

Returned by all Rest methods. Covers all possible errors in the HTTP layer.

FluxerApiError

Occurs when the server returns a JSON error with code and message fields.

FieldError


HttpError

Occurs when the status is >= 400, but the response body is not a recognized JSON error.

RateLimitError

Occurs after all retry attempts are exhausted with a 429 status.

Examples