tadpole/rest
REST request builders, rate-limit header parsing, response checks. Rate-limit state is derived from response headers and 429 bodies, never from a hardcoded table.
Types
pub type Method {
GET
POST
PUT
DELETE
PATCH
HEAD
OPTIONS
}
Constructors
-
GET -
POST -
PUT -
DELETE -
PATCH -
HEAD -
OPTIONS
pub type RateLimitHeaders {
RateLimitHeaders(
limit: option.Option(Int),
remaining: option.Option(Int),
reset: option.Option(Int),
reset_after: option.Option(Float),
bucket: option.Option(String),
retry_after: option.Option(Int),
is_global: Bool,
)
}
Constructors
-
RateLimitHeaders( limit: option.Option(Int), remaining: option.Option(Int), reset: option.Option(Int), reset_after: option.Option(Float), bucket: option.Option(String), retry_after: option.Option(Int), is_global: Bool, )
pub type RestClient {
RestClient(
token: String,
timeout_ms: Int,
retry_on_429: Bool,
max_retries: Int,
)
}
Constructors
-
RestClient( token: String, timeout_ms: Int, retry_on_429: Bool, max_retries: Int, )
pub type RestRequest {
RestRequest(
method: Method,
path: String,
headers: List(#(String, String)),
body: option.Option(String),
audit_log_reason: option.Option(String),
)
}
Constructors
-
RestRequest( method: Method, path: String, headers: List(#(String, String)), body: option.Option(String), audit_log_reason: option.Option(String), )
pub type RestResponse {
RestResponse(
status: Int,
headers: List(#(String, String)),
body: String,
rate_limit_headers: option.Option(RateLimitHeaders),
)
}
Constructors
-
RestResponse( status: Int, headers: List(#(String, String)), body: String, rate_limit_headers: option.Option(RateLimitHeaders), )
Values
pub fn authorization_header(token: String) -> #(String, String)
pub fn delete(path: String) -> RestRequest
pub fn get(path: String) -> RestRequest
pub fn header(
headers: List(#(String, String)),
name: String,
) -> option.Option(String)
Case-insensitive: HTTP header names are case-insensitive per spec, and proxies/clients normalize casing unpredictably.
pub fn is_client_error(response: RestResponse) -> Bool
pub fn is_forbidden(response: RestResponse) -> Bool
pub fn is_not_found(response: RestResponse) -> Bool
pub fn is_ok(response: RestResponse) -> Bool
pub fn is_rate_limited(response: RestResponse) -> Bool
pub fn is_server_error(response: RestResponse) -> Bool
pub fn is_unauthorized(response: RestResponse) -> Bool
pub fn new_client(
token: String,
timeout_ms: Int,
retry_on_429: Bool,
max_retries: Int,
) -> RestClient
pub fn parse_rate_limit_headers(
headers: List(#(String, String)),
) -> RateLimitHeaders
Discord may omit any of these headers; each degrades to None.
pub fn patch(path: String, body: String) -> RestRequest
pub fn post(path: String, body: String) -> RestRequest
pub fn put(path: String, body: String) -> RestRequest
pub fn with_audit_log_reason(
request: RestRequest,
reason: String,
) -> RestRequest
pub fn with_header(
request: RestRequest,
name: String,
value: String,
) -> RestRequest