gossamer/request

Types

pub type Fields {
  Fields(
    method: http_method.HttpMethod,
    url: String,
    headers: headers.Headers,
    cache: request_cache.RequestCache,
    credentials: request_credentials.RequestCredentials,
    destination: request_destination.RequestDestination,
    mode: request_mode.RequestMode,
    priority: request_priority.RequestPriority,
    redirect: request_redirect.RequestRedirect,
    referrer_policy: referrer_policy.ReferrerPolicy,
    signal: abort_signal.AbortSignal,
    referrer: String,
    integrity: String,
    is_keepalive: Bool,
    body: option.Option(
      readable_stream.ReadableStream(uint8_array.Uint8Array),
    ),
  )
}

Constructors

  • Arguments

    cache

    The cache mode. Always request_cache.Default on Deno (denoland/deno#27763).

    credentials

    The credentials mode. Always request_credentials.SameOrigin on Deno (denoland/deno#27763); always request_credentials.Include on Bun against the spec’s same-origin default (oven-sh/bun#17052).

    destination

    The kind of resource requested. Always request_destination.Empty for user-created requests.

    mode

    The mode. Always request_mode.Cors on Deno (denoland/deno#27763).

    priority

    The priority hint. Always request_priority.Auto — no runtime currently exposes the getter.

    referrer_policy

    The referrer policy. Always referrer_policy.StrictOriginWhenCrossOrigin on Deno (denoland/deno#27763) and Bun (oven-sh/bun#30124).

    referrer

    The referrer. Always "about:client" on Deno (denoland/deno#27763); always "" on Bun (oven-sh/bun#30124).

    integrity

    The subresource integrity metadata. Always "" on Deno (denoland/deno#27763) and Bun (oven-sh/bun#30124).

    is_keepalive

    Whether the request can outlive the global in which it was created. Always False on Deno (denoland/deno#27763) and Bun (oven-sh/bun#30124).

    body

    The body stream, or None if the request has no body. Single-use: consuming it (via blob, text, json, etc., or via the stream itself) drains all references to it. Some(stream) means a stream object exists; whether it is still readable is governed by is_body_used and the stream’s own state.

An HTTP request.

Several properties read back differently than what was set in init on non-compliant runtimes. Tracked upstream as https://github.com/denoland/deno/issues/27763 (Deno) and https://github.com/oven-sh/bun/issues/30124 (Bun, plus https://github.com/oven-sh/bun/issues/17052 for credentials). See per-property doc comments for specifics.

See Request on MDN.

pub type Request

Values

pub fn array_buffer(
  of request: Request,
) -> promise.Promise(
  Result(array_buffer.ArrayBuffer, js_error.JsError),
)

Reads the request body as an ArrayBuffer. Returns an error if the body has already been consumed or cannot be read.

pub fn blob(
  of request: Request,
) -> promise.Promise(Result(blob.Blob, js_error.JsError))

Reads the request body as a Blob. Returns an error if the body has already been consumed or cannot be read.

pub fn body(
  of request: Request,
) -> Result(
  readable_stream.ReadableStream(uint8_array.Uint8Array),
  Nil,
)

The body stream, or an error if the request has no body. Single-use: consuming it (via blob, text, json, etc., or via the stream itself) drains all references to it. Ok(stream) means a stream object exists; whether it is still readable is governed by is_body_used and the stream’s own state.

pub fn bytes(
  of request: Request,
) -> promise.Promise(
  Result(uint8_array.Uint8Array, js_error.JsError),
)

Reads the request body as a Uint8Array. Returns an error if the body has already been consumed or cannot be read.

pub fn cache(of request: Request) -> request_cache.RequestCache

The cache mode. Always request_cache.Default on Deno (denoland/deno#27763).

pub fn clone(
  request: Request,
) -> Result(Request, js_error.JsError)

Creates a clone of the request. Returns an error if the body has already been consumed or is locked to a reader.

pub fn credentials(
  of request: Request,
) -> request_credentials.RequestCredentials

The credentials mode. Always request_credentials.SameOrigin on Deno (denoland/deno#27763); always request_credentials.Include on Bun against the spec’s same-origin default (oven-sh/bun#17052).

pub fn destination(
  of request: Request,
) -> request_destination.RequestDestination

The kind of resource requested. Always request_destination.Empty for user-created requests.

pub fn form_data(
  of request: Request,
) -> promise.Promise(Result(form_data.FormData, js_error.JsError))

Reads the request body as FormData. Returns an error if the body has already been consumed or the Content-Type is not multipart/form-data or application/x-www-form-urlencoded.

pub fn from_request(
  existing: Request,
) -> Result(Request, js_error.JsError)

Creates a new Request by copying existing. The body is shared with existing — after copying, existing’s body can no longer be consumed. Returns an error if existing’s body is already disturbed or locked.

pub fn from_request_with(
  existing: Request,
  with init: List(RequestInit),
) -> Result(Request, js_error.JsError)

Creates a new Request by copying existing and applying init options. Returns an error if existing’s body is disturbed or locked, or init contains an invalid method, header, or mode.

pub fn from_url(
  url: url.URL,
) -> Result(Request, js_error.JsError)

Creates a new Request from url. Returns an error if url contains credentials (the Fetch spec rejects user:pass@ URLs).

pub fn from_url_string(
  url: String,
) -> Result(Request, js_error.JsError)

Creates a new Request from a URL given as a string. Returns an error if url is not a valid URL or contains credentials (the Fetch spec rejects user:pass@ URLs).

pub fn from_url_string_with(
  url: String,
  with init: List(RequestInit),
) -> Result(Request, js_error.JsError)

Creates a new Request from a URL given as a string, with init options. Returns an error if url is not a valid URL or contains credentials, or init contains an invalid method, header, or mode.

pub fn from_url_with(
  url: url.URL,
  with init: List(RequestInit),
) -> Result(Request, js_error.JsError)

Creates a new Request from url with init options. Returns an error if url contains credentials, or init contains an invalid method, header, or mode.

pub fn headers(of request: Request) -> headers.Headers
pub fn integrity(of request: Request) -> String

The subresource integrity metadata. Always "" on Deno (denoland/deno#27763) and Bun (oven-sh/bun#30124).

pub fn is_body_used(request: Request) -> Bool
pub fn is_keepalive(request: Request) -> Bool

Whether the request can outlive the global in which it was created. Always False on Deno (denoland/deno#27763) and Bun (oven-sh/bun#30124).

pub fn json(
  of request: Request,
) -> promise.Promise(Result(dynamic.Dynamic, js_error.JsError))

Reads the request body and parses it as JSON. Returns an error if the body has already been consumed or the content is not valid JSON.

pub fn method(of request: Request) -> http_method.HttpMethod
pub fn mode(of request: Request) -> request_mode.RequestMode

The mode. Always request_mode.Cors on Deno (denoland/deno#27763).

pub fn priority(
  of request: Request,
) -> request_priority.RequestPriority

The priority hint. Always request_priority.Auto — no runtime currently exposes the getter.

pub fn redirect(
  of request: Request,
) -> request_redirect.RequestRedirect
pub fn referrer(of request: Request) -> String

The referrer. Always "about:client" on Deno (denoland/deno#27763); always "" on Bun (oven-sh/bun#30124).

pub fn referrer_policy(
  of request: Request,
) -> referrer_policy.ReferrerPolicy

The referrer policy. Always referrer_policy.StrictOriginWhenCrossOrigin on Deno (denoland/deno#27763) and Bun (oven-sh/bun#30124).

pub fn signal(of request: Request) -> abort_signal.AbortSignal
pub fn text(
  of request: Request,
) -> promise.Promise(Result(String, js_error.JsError))

Reads the request body as text. Returns an error if the body has already been consumed or cannot be read.

pub fn to_fields(request: Request) -> Fields
pub fn url(of request: Request) -> String
Search Document