the-sett/elm-aws-core/1.2.0

NOTE: the latest version is 9.0.0

AWS.Core.Http

AWS requests and responses.

Table of Contents

Examples assume the following imports:

import Json.Decode

Requests

type alias Request a =
Unsigned a

Holds an unsigned AWS HTTP request.

request : Method -> Path -> Body -> Decoder a -> Request a

Create an AWS HTTP unsigned request.

request GET "/" emptyBody Json.Decode.value
    |> toString
--> "{ method = \"GET\", path = \"/\", body = Empty, decoder = <decoder>, headers = [], query = [], responseParser = Nothing }"
addHeaders : List ( String, String ) -> Request a -> Request a

Appends headers to an AWS HTTP unsigned request.

request GET "/" emptyBody Json.Decode.value
    |> addHeaders
        [ ( "x-custom-1", "value 1" )
        , ( "x-Custom-2", "value 2" )
        ]
    |> addHeaders
        [ ( "x-custom-3", "value 3" )
        ]
    |> toString
--> "{ method = \"GET\", path = \"/\", body = Empty, decoder = <decoder>, headers = [(\"x-custom-1\",\"value 1\"),(\"x-Custom-2\",\"value 2\"),(\"x-custom-3\",\"value 3\")], query = [], responseParser = Nothing }"
addQuery : List ( String, String ) -> Request a -> Request a

Appends query arguments to an AWS HTTP unsigned request.

request GET "/" emptyBody Json.Decode.value
    |> addQuery
        [ ( "key1", "value 1" )
        , ( "Key2", "value 2" )
        ]
    |> addQuery
        [ ( "key3", "value 3" )
        ]
    |> toString
--> "{ method = \"GET\", path = \"/\", body = Empty, decoder = <decoder>, headers = [], query = [(\"key1\",\"value 1\"),(\"Key2\",\"value 2\"),(\"key3\",\"value 3\")], responseParser = Nothing }"
setResponseParser : (Response String -> Result Error a) -> Request a -> Request a

Set a parser for the entire Http.Response. Overrides the request decoder.

send : Service -> Credentials -> Request a -> Task Error a

Signs and sends an AWS Request.

type Method
= DELETE
| GET
| HEAD
| OPTIONS
| POST
| PUT

HTTP request methods.

type alias Path =
String

Request path.

Body

type alias Body =
Body

Holds a request body.

type alias MimeType =
String
emptyBody : Body

Create an empty body.

stringBody : MimeType -> String -> Body

Create a body with a custom MIME type and the given string as content.

stringBody "text/html" "<html><body><h1>Hello</h1></body></html>"
jsonBody : Value -> Body

Create a body containing a JSON value.

This will automatically add the Content-Type: application/json header.