Rolodex v0.10.1 Rolodex.Headers
Exposes functions and macros for defining reusable headers in route doc annotations or responses.
It exposes the following macros, which when used together will set up the headers:
headers/2
- for declaring the headersheader/3
- for declaring a single header for the set
It also exposes the following functions:
is_headers_module?/1
- determines if the provided item is a module that has defined a reusable headers setto_map/1
- serializes the headers module into a map
Link to this section Summary
Functions
Sets a header field
Opens up the headers definition for the current module. Will name the headers set and generate a list of header fields based on the macro calls within
Determines if an arbitrary item is a module that has defined a reusable headers
set via Rolodex.Headers
macros
Serializes the Rolodex.Headers
metadata into a formatted map
Link to this section Functions
field(identifier, type, opts \\ []) (macro)
Sets a header field.
Accepts
identifier
- the header nametype
- the header field typeopts
(optional) - additional metadata. SeeField.new/1
for a list of valid options.
headers(name, list) (macro)
Opens up the headers definition for the current module. Will name the headers set and generate a list of header fields based on the macro calls within.
Accepts
name
- the headers nameblock
- headers shape definition
Example
defmodule SimpleHeaders do
use Rolodex.Headers
headers "SimpleHeaders" do
field "X-Rate-Limited", :boolean
field "X-Per-Page", :integer, desc: "Number of items in the response"
end
end
is_headers_module?(mod)
Determines if an arbitrary item is a module that has defined a reusable headers
set via Rolodex.Headers
macros
Example
defmodule SimpleHeaders do
...> use Rolodex.Headers
...> headers "SimpleHeaders" do
...> field "X-Rate-Limited", :boolean
...> end
...> end
iex>
# Validating a headers module
Rolodex.Headers.is_headers_module?(SimpleHeaders)
true
iex> # Validating some other module
iex> Rolodex.Headers.is_headers_module?(OtherModule)
false
to_map(mod)
Serializes the Rolodex.Headers
metadata into a formatted map
Example
iex> defmodule SimpleHeaders do
...> use Rolodex.Headers
...>
...> headers "SimpleHeaders" do
...> field "X-Rate-Limited", :boolean
...> field "X-Per-Page", :integer, desc: "Number of items in the response"
...> end
...> end
iex>
iex> Rolodex.Headers.to_map(SimpleHeaders)
%{
"X-Per-Page" => %{desc: "Number of items in the response", type: :integer},
"X-Rate-Limited" => %{type: :boolean}
}