Aino.Middleware (aino v0.1.0)

Middleware functions for processing a request into a response

Included in Aino are common functions that deal with requests, such as parsing the POST body for form data or parsing query/path params.

Link to this section Summary

Functions

Common middleware that process low level request data

Processes the Cookie request header

Processes request headers

Stores the request method on the token

Merge params into a single map

Stores the request path on the token on the key :path

Stores query parameters on the token

Processes the request body

Link to this section Functions

Common middleware that process low level request data

Processes the request:

  • method
  • path
  • headers
  • query parameters
  • parses response body
  • parses cookies

Processes the Cookie request header

Defaults to an empty map if no Cookie header is present.

Stores cookies as a map in the key :cookies

Processes request headers

Downcases all of the headers and stores in the key :headers

Stores the request method on the token

Downcases and converts to an atom on the key :method

iex> request = %Aino.Request{method: :GET}
iex> token = %{request: request}
iex> token = Middleware.method(token)
iex> token.method
:get

Merge params into a single map

Merges in the following order:

  • Path params
  • Query params
  • POST body

Stores the request path on the token on the key :path

iex> request = %Aino.Request{path: ["orders", "10"]}
iex> token = %{request: request}
iex> token = Middleware.path(token)
iex> token.path
["orders", "10"]
Link to this function

query_params(token)

Stores query parameters on the token

Converts map and stores on the key :query_params

iex> request = %Aino.Request{args: [{"key", "value"}]}
iex> token = %{request: request}
iex> token = Middleware.query_params(token)
iex> token.query_params
%{"key" => "value"}
Link to this function

request_body(token)

Processes the request body

Only if the request should have a body (e.g. POST requests)

Handles the following content types:

  • application/x-www-form-urlencoded
  • application/json