Helpers and struct for building HTTP responses.
Most callers will use the simple map form:
%{status: 200, body: "ok"}
%{status: 201, json: %{result: "accepted"}}This module makes it easy to construct responses and turn them into raw wire-format bytes to be sent via TCP.
Summary
Functions
Builds an empty-body response.
Builds a JSON response using Jason for encoding.
Builds a plain text response.
Converts a response specification (map or struct) into raw HTTP/1.1 bytes.
Types
Functions
@spec empty( non_neg_integer(), keyword() ) :: t()
Builds an empty-body response.
@spec json(non_neg_integer(), map() | list(), keyword()) :: t()
Builds a JSON response using Jason for encoding.
@spec text(non_neg_integer(), iodata(), keyword()) :: t()
Builds a plain text response.
@spec to_iodata(map() | t(), HttpDouble.Request.t() | nil) :: iodata()
Converts a response specification (map or struct) into raw HTTP/1.1 bytes.
When request is provided, it is used for behaviours like HEAD responses
(no body even when one is present).