http-api-data
Converting to/from HTTP API data like URL pieces, headers and query parameters.
http-api-data
This package defines typeclasses used for converting Haskell data types to and from HTTP API data.
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]
["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)
Contributing
Contributions and bug reports are welcome!
- base >= 4.12.0.0 && < 4.23
- bytestring >= 0.10.8.2 && < 0.13
- containers >= 0.6.0.1 && < 0.9
- text >= 1.2.3.0 && < 1.3 || >=2.0 && <2.2
- cookie >= 0.5.1 && < 0.6
- hashable >= 1.4.4.0 && < 1.6
- http-types >= 0.12.4 && < 0.13
- text-iso8601 >= 0.1.1 && < 0.2
- tagged >= 0.8.8 && < 0.9
- time-compat >= 1.9.5 && < 1.10
- uuid-types >= 1.0.6 && < 1.1
- text-show >= 3.10.5 && <3.12
- 0.7
- 0.6.3
- 0.6.2
- 0.6.1
- 0.6
- 0.5.1
- 0.5
- 0.4.3
- 0.4.2
- 0.4.1.1
- 0.4.1
- 0.4
- 0.3.10
- 0.3.9
- 0.3.8.1
- 0.3.8
- 0.3.7.2
- 0.3.7.1
- 0.3.7
- 0.3.6
- 0.3.5
- 0.3.4
- 0.3.3
- 0.3.2
- 0.3.1
- 0.3
- 0.2.4
- 0.2.3
- 0.2.2
- 0.2.1
- 0.2
- 0.1.1.1
- 0.1.1
- 0.1.0
