Serverless.Plug

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)

type Plug config model route

[]

Represents a pipeline or section of a pipeline.


Building Pipelines

Use these functions to build your pipelines.


pipeline : Serverless.Plug.Plug config model route

Begins a pipeline.

Build the pipeline by chaining plugs with plug, loop, fork, and nest.

size pipeline
--> 0

plug : (Serverless.Conn.Conn config model route -> Serverless.Conn.Conn config model route) -> Serverless.Plug.Plug config model route -> Serverless.Plug.Plug config model route

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

nest : Serverless.Plug.Plug config model route -> Serverless.Plug.Plug config model route -> Serverless.Plug.Plug config model route

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

Applying Pipelines


apply : Serverless.Plug.Plug config model route -> Serverless.Conn.Conn config model route -> Serverless.Conn.Conn config model route

Basic pipeline update function.


Misc

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.


size : Serverless.Plug.Plug config model route -> Basics.Int

The number of plugs in a pipeline