Serverless.Conn.Request

Query attributes of the HTTP request.

Table of Contents

Request Types


type Request

[]

An HTTP request.


type Method

= Method

[['CONNECT', []], ['DELETE', []], ['GET', []], ['HEAD', []], ['OPTIONS', []], ['PATCH', []], ['POST', []], ['PUT', []], ['TRACE', []]]

HTTP request method.

-- to use shorthand notation
import Serverless.Conn.Request exposing (Method(..))

type Scheme

= Scheme

[['Http', []], ['Https', []]]

Request scheme (a.k.a. protocol).

-- to use shorthand notation
import Serverless.Conn.Request exposing (Scheme(..))

Routing

These attributes are typically involved in routing requests. See the Routing Demo for an example.


url : Serverless.Conn.Request.Request -> String.String

The requested URL if it parsed correctly.


method : Serverless.Conn.Request.Request -> Serverless.Conn.Request.Method

HTTP request method.

case Request.method req of
    Request.GET ->
        -- handle get...

    Request.POST ->
        -- handle post...

    _ ->
        -- method not supported...

path : Serverless.Conn.Request.Request -> String.String

Request path.

While you can access this attribute directly, it is better to provide a parseRoute function to the framework.


queryString : Serverless.Conn.Request.Request -> String.String

The original query string.

While you can access this attribute directly, it is better to provide a parseRoute function to the framework.


Body

Functions to access the request body and attempt a cast to a content type. See the Forms Demo for an example.


body : Serverless.Conn.Request.Request -> Serverless.Conn.Body.Body

Request body.


asText : Serverless.Conn.Body.Body -> Result.Result String.String String.String

Extract the String from the body.


asJson : Serverless.Conn.Body.Body -> Result.Result String.String Json.Encode.Value

Extract the JSON value from the body.


Other Attributes


header : String.String -> Serverless.Conn.Request.Request -> Maybe.Maybe String.String

Get a request header by name.

Headers are normalized such that the keys are always lower-case.


query : String.String -> Serverless.Conn.Request.Request -> Maybe.Maybe String.String

Get a query argument by name.


endpoint : Serverless.Conn.Request.Request -> ( Serverless.Conn.Request.Scheme, String.String, Basics.Int )

Describes the server endpoint to which the request was made.

( scheme, host, port_ ) =
    Request.endpoint req
  • scheme is either Request.Http or Request.Https
  • host is the hostname as taken from the "host" request header
  • port_ is the port, for example 80 or 443

stage : Serverless.Conn.Request.Request -> String.String

Serverless deployment stage.

See https://serverless.com/framework/docs/providers/aws/guide/deploying/


methodToString : Serverless.Conn.Request.Method -> String.String

Gets the HTTP Method as a String, like 'GET', 'PUT', etc.


Misc

These functions are typically not needed when building an application. They are used internally by the framework.


init : Serverless.Conn.Request.Request

Initialize an empty Request.

Exposed for unit testing. Incoming connections initialize requests using JSON decoders.


decoder : Json.Decode.Decoder Serverless.Conn.Request.Request

JSON decoder for HTTP requests.


methodDecoder : Json.Decode.Decoder Serverless.Conn.Request.Method

JSON decoder for the HTTP request method.


schemeDecoder : Json.Decode.Decoder Serverless.Conn.Request.Scheme

JSON decoder for the request scheme (a.k.a. protocol)