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

Safe HaskellNone
LanguageHaskell2010

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
>>> parseUrlPieces ["true", "false", "undefined"] :: Either Text [Bool]
Left "could not parse: `undefined'"

Numbers:

>>> toQueryParam 45.2
"45.2"
>>> parseQueryParam "452" :: Either Text Int
Right 452
>>> toQueryParams [1..5] :: [Text]
["1","2","3","4","5"]
>>> parseQueryParams ["127", "255"] :: Either Text [Int8]
Left "out of bounds: `255' (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.

WARNING: Do not derive this using DeriveAnyClass as the generated instance will loop indefinitely.

Minimal complete definition

toUrlPiece | toQueryParam

Methods

toUrlPiece :: a -> Text Source #

Convert to URL path piece.

toEncodedUrlPiece :: a -> Builder Source #

Convert to a URL path piece, making sure to encode any special chars. The default definition uses encodePathSegmentsRelative, but this may be overriden with a more efficient version.

toHeader :: a -> ByteString Source #

Convert to HTTP header value.

toQueryParam :: a -> Text Source #

Convert to query param value.

Instances
ToHttpApiData Bool Source # 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData Char Source # 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData Double Source # 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData Float Source # 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData Int Source # 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData Int8 Source # 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData Int16 Source # 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData Int32 Source # 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData Int64 Source # 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData Integer Source # 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData Natural Source # 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData Ordering Source # 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData Word Source # 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData Word8 Source # 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData Word16 Source # 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData Word32 Source # 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData Word64 Source # 
Instance details

Defined in Web.Internal.HttpApiData

ToHttpApiData () Source #
>>> toUrlPiece ()
"_"
Instance details

Defined in Web.Internal.HttpApiData