Defining an HTTP response struct
It’s always a good idea to define a struct to represent the structure of data you are expecting to work with. In this package, we will be working with HTTP responses, as our responder modules will be responding with them, and we will also be translating them into stringified documents to respond with. So, let’s go ahead and define the struct module:
lib/goldcrest_http_response.ex
defmodule Goldcrest.HTTPResponse do defstruct headers: %{}, body: "", status: 200 @type t :: %__MODULE__{ headers: map(), body: String.t(), status: integer() } @http_version 1.1 def to_string( %__MODULE__{ status: status, body: body } = http_response ) do """ ...