the-sett / elm-serverless / Serverless.Conn.Request

Query attributes of the HTTP request.

Table of Contents

Request Types


type Request

An HTTP request.


type 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
    = 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 : Request -> String

The requested URL if it parsed correctly.

method : Request -> Method

HTTP request method.

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

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

    _ ->
        -- method not supported...

path : Request -> String

Request path.

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

queryString : Request -> 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 : Request -> Serverless.Conn.Body.Body

Request body.

Other Attributes

header : String -> Request -> Maybe String

Get a request header by name.

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

query : String -> Request -> Maybe String

Get a query argument by name.

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

Describes the server endpoint to which the request was made.

( scheme, host, port_ ) =
    Request.endpoint req

stage : Request -> String

Serverless deployment stage.

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

methodToString : Method -> 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. They may be useful when debugging or writing unit tests.

init : Request

Initialize an empty Request.

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

decoder : Json.Decode.Decoder Request

JSON decoder for HTTP requests.

methodDecoder : Json.Decode.Decoder Method

JSON decoder for the HTTP request method.

schemeDecoder : Json.Decode.Decoder Scheme

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