Sap.Combinators
Conveniences for creating combinators.
Combinators, a fancy name for simple functions meant to be composed with one another, are tasked with one of two goals:
- filter requests based on some criteria
- build up a response
The power of these functions comes from the ability to compose them in any order. There is no clear separation of each type of combinators, so a filtering combinator can be used both before and after a building combinator and vice versa.
Summary
Types
A combinator must accept a Plug.Conn
and return Sap.Context
Functions
Allows for multiple options at a decision tree node. choose/1
combinators
can be nested to create multiple decision paths
Only permits HTTP GET requests in the rest of a node’s definition
Sets the response status code of 200 Ok
and, if present, the given
response body
Filters out requests that do not match a given path
. The filter depends
on an exact match of the requested path and does not yet support
capturing path segments
Sets the response header for the rest of a node to application/json
Types
combinator :: (Plug.Conn.t -> Sap.Context.t)
A combinator must accept a Plug.Conn
and return Sap.Context
.
Functions
Specs
choose([combinator]) :: combinator
Allows for multiple options at a decision tree node. choose/1
combinators
can be nested to create multiple decision paths.
Specs
ok :: combinator
Sets the response status code of 200 Ok
and, if present, the given
response body.
Specs
path(String.t) :: combinator
Filters out requests that do not match a given path
. The filter depends
on an exact match of the requested path and does not yet support
capturing path segments.
Specs
resp_json :: combinator
Sets the response header for the rest of a node to application/json
.