Runlight.Http.Request (runlight v0.1.0)

Copy Markdown View Source

A request, shaped like the Fetch API's Request so the routes read as the TypeScript SDK's do: an absolute URL, a method, headers, and the body as text. Runlight.Plug makes one from a Plug.Conn; a test or another server can make one with new/2.

remote_address is the address the connection came from, used for the visitor's daily hash and the rate limit when no trusted proxy header names the client.

Summary

Functions

A header's value, every one joined with ", ", or nil.

The body as JSON: {:ok, value} or :error, as request.json() resolves or rejects.

A request for url (absolute). Options: :method (default "GET"), :headers (a map or list of pairs), :body (text), and :remote_address.

The body as text.

The parsed URL.

The same request with other parts, as new Request(request, init) makes one.

Types

t()

@type t() :: %Runlight.Http.Request{
  body: binary(),
  headers: Runlight.Http.Headers.t(),
  method: String.t(),
  ref: reference() | nil,
  remote_address: String.t(),
  url: String.t()
}

Functions

header(request, name)

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

A header's value, every one joined with ", ", or nil.

json(r)

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

The body as JSON: {:ok, value} or :error, as request.json() resolves or rejects.

new(url, opts \\ [])

@spec new(String.t(), keyword()) :: t()

A request for url (absolute). Options: :method (default "GET"), :headers (a map or list of pairs), :body (text), and :remote_address.

text(request)

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

The body as text.

url(request)

@spec url(t()) :: Runlight.Url.t()

The parsed URL.

with(r, changes)

@spec with(t(), keyword()) :: t()

The same request with other parts, as new Request(request, init) makes one.