Sap v0.0.3 Sap.Combinators View Source

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.

Link to this section 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

Link to this section Types

Link to this type combinator() View Source
combinator() :: (Plug.Conn.t() -> Sap.Context.t())

A combinator must accept a Plug.Conn and return Sap.Context.

Link to this section 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.