This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.

Exts.Http

Extensions to the Http library.

cgiParameters : List ( String, String ) -> String

Encode a CGI parameter list.

formBody : List ( String, String ) -> Body

Put some key-value pairs in the body of your Request. This will automatically add the Content-Type: application/x-www-form-urlencoded header.

module Exts.Http exposing
    ( cgiParameters
    , formBody
    )

{-| Extensions to the `Http` library.

@docs cgiParameters
@docs formBody

-}

import Http exposing (..)
import String
import Url exposing (percentEncode)


{-| Encode a CGI parameter pair.
-}
cgiParameter : ( String, String ) -> String
cgiParameter ( key, value ) =
    percentEncode key ++ "=" ++ percentEncode value


{-| Encode a CGI parameter list.
-}
cgiParameters : List ( String, String ) -> String
cgiParameters =
    List.map cgiParameter
        >> String.join "&"


{-| Put some key-value pairs in the body of your `Request`. This will automatically
add the `Content-Type: application/x-www-form-urlencoded` header.
-}
formBody : List ( String, String ) -> Body
formBody =
    cgiParameters
        >> stringBody "application/x-www-form-urlencoded"