http-api-data-0.1.0: Converting to/from HTTP API data like URL pieces, headers and query parameters.

Safe HaskellSafe
LanguageHaskell98

Web.HttpApiData

Contents

Description

Convert Haskell values to and from HTTP API data such as URL pieces, headers and query parameters.

Synopsis

Examples

Booleans:

>>> toUrlPiece True
"true"
>>> parseUrlPiece "false" :: Either Text Bool
Right False
>>> parseUrlPiece "something else" :: Either Text Bool
Left "could not parse: `something else'"

Numbers:

>>> toUrlPiece 45.2
"45.2"
>>> parseUrlPiece "452" :: Either Text Int
Right 452
>>> parseUrlPiece "256" :: Either Text Int8
Left "out of bounds: `256' (should be between -128 and 127)"

Strings:

>>> toHeader "hello"
"hello"
>>> parseHeader "world" :: Either Text String
Right "world"

Calendar day:

>>> toQueryParam (fromGregorian 2015 10 03)
"2015-10-03"
>>> toGregorian <$> parseQueryParam "2016-12-01"
Right (2016,12,1)

Classes

class ToHttpApiData a where Source

Convert value to HTTP API data.

Minimal complete definition

toUrlPiece | toQueryParam

Methods

toUrlPiece :: a -> Text Source

Convert to URL path piece.

toHeader :: a -> ByteString Source

Convert to HTTP header value.

toQueryParam :: a -> Text Source

Convert to query param value.

class FromHttpApiData a where Source

Parse value from HTTP API data.

Minimal complete definition

parseUrlPiece | parseQueryParam

Methods

parseUrlPiece :: Text -> Either Text a Source

Parse URL path piece.

parseHeader :: ByteString -> Either Text a Source

Parse HTTP header value.

parseQueryParam :: Text -> Either Text a Source

Parse query param value.