A pipeline is a sequence of functions which transform the connection, optionally sending back an HTTP response at each step. We use the term plug to mean a single function that is part of the pipeline. But a pipeline is also just a plug and so pipelines can be composed from other pipelines.
Examples below assume the following imports:
import Serverless.Conn exposing (updateResponse) import Serverless.Conn.Body exposing (text) import Serverless.Conn.Response exposing (addHeader, setBody, setStatus)
Represents a pipeline or section of a pipeline.
Use these functions to build your pipelines.
Begins a pipeline.
Build the pipeline by chaining plugs with plug, loop, fork, and nest.
size pipeline --> 0
Extend the pipeline with a simple plug.
A plug just transforms the connection. For example,
pipeline |> plug (updateResponse <| setBody <| text "Ok" ) |> plug (updateResponse <| setStatus 200) |> size --> 2
Extends the pipeline with a plug.
This is the most general of the pipeline building functions. Since it just accepts a plug, and since a plug can be a pipeline, it can be used to extend a pipeline with a group of plugs.
pipeline |> nest (pipeline |> plug (updateResponse <| addHeader ( "key", "value" )) -- ... ) |> plug (updateResponse <| setStatus 200) |> size --> 2
Basic pipeline update function.
These functions are typically not needed when building an application. They are used internally by the framework. They are useful when debugging or writing unit tests.
The number of plugs in a pipeline