Hcs.Pipeline

hcs · API reference

Ordered collections of plugs.

Pipelines make reusable groups of middleware for route scopes. Typical apps define one pipeline for browser requests and another for API requests, then attach them to router scopes or endpoints.

Ordered plug collections.

A pipeline is a reusable list of plugs applied in order to a request handler. Use pipelines to keep route scopes consistent:

let browser =
  Hcs.Pipeline.empty |> fun p ->
  Hcs.Pipeline.plug p (Hcs.Plug.Logger.create logger) |> fun p ->
  Hcs.Pipeline.plug p (Hcs.Plug.Csrf.create ~secret)

let routes =
  Hcs.Router.scope ~through:browser "/admin"
    [ Hcs.Router.Route.get "/" admin_index ]

A plug added first runs before later plugs.

type t =
  ((Server.request -> Server.response) ->
    Server.request ->
    Server.response)
    list

A reusable ordered collection of plugs.

val empty : t

The empty pipeline.

val create : 
  ((Server.request -> Server.response) ->
    Server.request ->
    Server.response)
    list ->
  t

Build a pipeline from an explicit plug list.

val plug : 
  t ->
  ((Server.request -> Server.response) -> Server.request -> Server.response) ->
  t

Append a plug to the end of the pipeline.

val plug_first : 
  t ->
  ((Server.request -> Server.response) -> Server.request -> Server.response) ->
  t

Prepend a plug so it runs before existing plugs.

val compose : t -> t -> t

compose a b returns a pipeline that runs a then b.

val to_plug : 
  t ->
  (Server.request -> Server.response) ->
  Server.request ->
  Server.response

Convert the whole pipeline into one plug.

val apply : 
  t ->
  (Server.request -> Server.response) ->
  Server.request ->
  Server.response

Apply the pipeline to a handler.

val is_empty : t -> bool

true when the pipeline contains no plugs.

val length : t -> int

Number of plugs in the pipeline.