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

choose(parts)

Specs

choose([combinator]) :: combinator

Allows for multiple options at a decision tree node. choose/1 combinators can be nested to create multiple decision paths.

get()

Specs

get :: combinator

Only permits HTTP GET requests in the rest of a node’s definition.

ok()

Specs

ok :: combinator

Sets the response status code of 200 Ok and, if present, the given response body.

ok(resp)

Specs

path(path)

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.

resp_json()

Specs

resp_json :: combinator

Sets the response header for the rest of a node to application/json.