glyde/rest/seg

The concrete path and the rate-limit template come out of one walk of the same typed segments, so they cannot drift apart. A path glyde does not wrap goes through from_path, which classifies the raw segments and then takes the same walk.

Types

pub type Resolved {
  Resolved(path: String, route: route.Route)
}

Constructors

pub opaque type Seg

Values

pub fn channel(channel_id: id.Id(id.Channel)) -> Seg

A channel id, a major parameter: erased from the template, kept in the bucket key.

pub fn from_path(
  method: http.Method,
  path: String,
  sublimit: route.Sublimit,
) -> route.Route

The rate-limit identity of a path glyde does not wrap, read back out of the path string. It classifies the segments and then takes the walk resolve takes, so a hand-written path and a built one cannot disagree about which bucket they are in.

Only ids and the two token positions are replaced. Any other variable segment stays in the template, so keep further secrets out of the path.

pub fn guild(guild_id: id.Id(id.Guild)) -> Seg

A guild id, the other single-segment major parameter.

pub fn id(snowflake: id.Id(kind)) -> Seg

A non-major id: a message id, a user id inside a guild route. Erased from the template and absent from the bucket key.

pub fn lit(text: String) -> Seg

A literal path segment, not percent-encoded: encoding one would turn @me into %40me, a different resource to Discord. For a constant only; text from a caller’s value goes through loose.

pub fn loose(text: String) -> Seg

A segment that is not a constant and is not an id glyde has a type for: it is percent-encoded in the path, and stays as written in the bucket template because there is nothing to replace it with. A snowflake is an ordinary id.

pub fn opaque_text(text: String) -> Seg

Free text that is neither an id nor a literal: an interaction token, an invite code. Erased from the template.

pub fn reaction(emoji: String) -> Seg

A reaction emoji. Discord buckets every reaction on a message together, so the emoji and everything after it leaves the template.

pub fn resolve(
  method: http.Method,
  segments: List(Seg),
) -> Resolved

Sublimit is left at NoSublimit: a path cannot know how old the message it deletes is. The caller sets that on the route.

pub fn webhook(
  hook: id.Id(id.Webhook),
  token: String,
) -> List(Seg)

A webhook’s id and token, one major parameter across two path segments. One value here, so half of it cannot reach a bucket key.

pub fn webhook_id(hook: id.Id(id.Webhook)) -> List(Seg)

The tokenless form, GET /webhooks/{webhook.id}, which Discord buckets by the id alone. One path segment, not two.

Search Document