Loopback.HTTPResponse (Loopback v0.1.0)

Copy Markdown View Source

A response to an intercepted HTTP request, as returned by the fakes.

Fields

  • :status - the status code, like 200.
  • :headers - a list of {name, value} tuples of strings. Defaults to [].
  • :body - the body as a binary. Defaults to "".

Summary

Types

t()

A response to an intercepted HTTP request.

Functions

Builds a response with body encoded as JSON, and a {"content-type", "application/json; charset=utf-8"} header prepended to headers.

Builds a response from a map or a keyword list of its fields.

Types

t()

@type t() :: %Loopback.HTTPResponse{
  body: binary(),
  headers: [{String.t(), String.t()}],
  status: non_neg_integer()
}

A response to an intercepted HTTP request.

Functions

json(status, body, headers \\ [])

@spec json(non_neg_integer(), term(), [{String.t(), String.t()}]) :: t()

Builds a response with body encoded as JSON, and a {"content-type", "application/json; charset=utf-8"} header prepended to headers.

Examples

Loopback.HTTPResponse.json(200, %{"id" => 123})

new(params)

@spec new(map() | keyword()) :: t()

Builds a response from a map or a keyword list of its fields.

Raises ArgumentError when :status is missing.

Examples

Loopback.HTTPResponse.new(status: 204)