Functions for querying and updating connections.
A connection with a request and response.
Connections are parameterized with config and model record types which are specific to the application. Config is loaded once on app startup, while model is set to a provided initial value for each incomming request.
Universally unique connection identifier.
Query and update your application specific data.
Application defined configuration
Application defined model
Transform and update the application defined model stored in the connection.
Get details about the HTTP request.
Universally unique Conn identifier
Request HTTP method
Get a request header by name
Update the response and send it.
Update a response and send it.
import Serverless.Conn.Response exposing (setBody, setStatus) import TestHelpers exposing (conn, responsePort) -- The following two expressions produce the same result conn |> respond ( 200, textBody "Ok" ) --> conn --> |> updateResponse --> ((setStatus 200) >> (setBody <| textBody "Ok")) --> |> send
Applies the given transformation to the connection response.
Does not do anything if the response has already been sent.
import Serverless.Conn.Response exposing (addHeader) import TestHelpers exposing (conn, getHeader) conn |> updateResponse (addHeader ( "Cache-Control", "no-cache" )) |> getHeader "cache-control" --> Just "no-cache"
Sends a connection response through the given port
Converts a conn to a sent conn, making it immutable.
The connection will be sent once the current update loop completes. This function is intended to be used by middleware, which cannot issue side-effects.
import TestHelpers exposing (conn) (unsent conn) == Just conn --> True (unsent <| toSent conn) == Nothing --> True
Just the same can if it has not been sent yet.
Apply an update function to a conn, but only if the conn is unsent.
Use these constructors to create response bodies with different content types.
A plain text body.
A JSON body.
A binary file.
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.
Initialize a new Conn.
Response as JSON encoded to a string.
This is the format the response takes when it gets sent through the response port.