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

HTTP Body


type Body

An HTTP request or response body.

Response Body

Use these constructors to create response bodies with different content types.

text : String -> Body

A plain text body.

json : Json.Encode.Value -> Body

A JSON body.

binary : String -> String -> Body

A binary file.

empty : Body

Create an empty body.

Request Body

Use these functions to check what kind of body a request has.

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

Extract the JSON value from the body.

asText : Body -> Result String String

Extract the String from the body.

isEmpty : Body -> Basics.Bool

Is the given body empty?

import Json.Encode exposing (list)

isEmpty (empty)
--> True

isEmpty (text "")
--> False

isEmpty (json (list []))
--> False

contentType : Body -> String

The content type of a given body.

import Json.Encode

contentType (text "hello")
--> "text/text"

contentType (json Json.Encode.null)
--> "application/json"

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.

decoder : Maybe String -> Json.Decode.Decoder Body

A decoder for an HTTP body, to JSON or plain text.

encode : Body -> Json.Encode.Value

An encoder for an HTTP body.

isBase64Encoded : Body -> Basics.Bool

Checks if a body should be base 64 encoded.