Runlight.Http.Response (runlight v0.1.0)

Copy Markdown View Source

An answer, shaped like the Fetch API's Response: a status, headers (a list of lowercase names and values, with one entry per Set-Cookie), and the body as a binary.

Summary

Functions

A header's value, or nil.

The body as JSON: {:ok, value} or :error.

An answer of body with a status and headers.

Whether the status is 2xx, as response.ok.

The answer with a header set, replacing any of that name.

The Set-Cookie headers.

The body as text.

Types

t()

@type t() :: %Runlight.Http.Response{
  body: binary(),
  headers: Runlight.Http.Headers.t(),
  status: non_neg_integer()
}

Functions

header(response, name)

@spec header(t(), String.t()) :: String.t() | nil

A header's value, or nil.

json(r)

@spec json(t()) :: {:ok, term()} | :error

The body as JSON: {:ok, value} or :error.

new(body, status \\ 200, headers \\ [])

@spec new(binary() | nil, non_neg_integer(), Enumerable.t()) :: t()

An answer of body with a status and headers.

ok?(response)

@spec ok?(t()) :: boolean()

Whether the status is 2xx, as response.ok.

put_header(r, name, value)

@spec put_header(t(), String.t(), String.t()) :: t()

The answer with a header set, replacing any of that name.

set_cookies(response)

@spec set_cookies(t()) :: [String.t()]

The Set-Cookie headers.

text(response)

@spec text(t()) :: String.t()

The body as text.