# `HttpDouble.Response`
[🔗](https://github.com/aszymanskiit/http_double/blob/main/lib/http_double/response.ex#L1)

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.

# `t`

```elixir
@type t() :: %HttpDouble.Response{
  body: iodata(),
  chunked?: boolean(),
  headers: [{String.t(), String.t()}],
  json: map() | list() | nil,
  status: non_neg_integer()
}
```

Simple HTTP response structure.

# `empty`

```elixir
@spec empty(
  non_neg_integer(),
  keyword()
) :: t()
```

Builds an empty-body response.

# `json`

```elixir
@spec json(non_neg_integer(), map() | list(), keyword()) :: t()
```

Builds a JSON response using Jason for encoding.

# `text`

```elixir
@spec text(non_neg_integer(), iodata(), keyword()) :: t()
```

Builds a plain text response.

# `to_iodata`

```elixir
@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).

---

*Consult [api-reference.md](api-reference.md) for complete listing*
