the-sett / elm-aws-core / AWS.KVEncode

KVEncode provides encoders to turn things into list of (String, String) which can be used to build headers or query parameters. The encoding is one that is accepted by many AWS services.

When encoding records (or objects) the following scheme is used:

A field with a simple value is encoded like this:

( "Field", "value" )

A field with a list of simple values is encoded like this:

[ ( "Field.member.1", "value1" )
, ( "Field.member.2", "value2" )
, ...
]

A field with a single object value is encoded like this:

[ ( "Field.InnerField1", "innerValue1" )
, ( "Field.InnerField2", "innerValue2" )
, ...
]

A field with a list of object values is encoded like this:

[ ( "Field.member.1.InnerField1", "innerValue1" )
, ( "Field.member.1.InnerField2", "innerValue2" )
, ...
]

Sets of KV String tuples and their encoder.


type KVPairs

Describes pairs of (String, String) tuples.

Note that this data structure also allows values on their own with no keys for the convenience of keeping this API in a similar shape to JSON encoders.


type KVField

A field of a record to be encoded in (String, String) form.

encode : KVPairs -> List ( String, String )

Encodes a set of KV pairs into List (String, String) form.

The keys in the output may be compound to describe a path through objects and arrays into some deeper data structure. The possible formats are described in the module level documentation above.

Note that only KVPairs that have keys are encoded by this. Simple values or lists do not have keys and will result in [] being returned. This only produces a non-empty result if the top-level KVPair passed in, describes an object.

Encoders for simple types and collections.

int : Basics.Int -> KVPairs

Encodes an Int as a String without a key.

float : Basics.Float -> KVPairs

Encodes a Float as a String without a key.

string : String -> KVPairs

Encodes a String without a key.

bool : Basics.Bool -> KVPairs

Encodes an Bool as a String ("true" or "false") without a key.

list : (a -> KVPairs) -> List a -> KVPairs

Encodes a list of items as KVPairs.

dict : (a -> KVPairs) -> Dict String a -> KVPairs

Combines a Dict with an encoder for its values into a set of KVPairs.

Encoders for objects with optional fields.

field : (a -> KVPairs) -> ( String, a ) -> KVField

Encodes a pair of (String, a) into KVPairs.

optional : (a -> KVPairs) -> ( String, Maybe a ) -> KVField

Encodes a pair of (String, Maybe a) into KVPairs.

Values that are Nothing are not encoded in the output, they are skipped over.

object : List KVField -> KVPairs

Encodes a list of fields as an object.