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)
listA reusable ordered collection of plugs.
val empty : tThe empty pipeline.
val create :
((Server.request -> Server.response) ->
Server.request ->
Server.response)
list ->
tBuild a pipeline from an explicit plug list.
val plug :
t ->
((Server.request -> Server.response) -> Server.request -> Server.response) ->
tAppend a plug to the end of the pipeline.
val plug_first :
t ->
((Server.request -> Server.response) -> Server.request -> Server.response) ->
tPrepend a plug so it runs before existing plugs.
val compose : t -> t -> tcompose a b returns a pipeline that runs a then b.
val to_plug :
t ->
(Server.request -> Server.response) ->
Server.request ->
Server.responseConvert the whole pipeline into one plug.
val apply :
t ->
(Server.request -> Server.response) ->
Server.request ->
Server.responseApply the pipeline to a handler.
val is_empty : t -> booltrue when the pipeline contains no plugs.
val length : t -> intNumber of plugs in the pipeline.