@hackage / http-api-data

Converting to/from HTTP API data like URL pieces, headers and query parameters.

Latest0.7

About

Metadata

  • Last updated , by NickolayKudasov
  • License BSD-3-Clause
  • Categories Web Development
  • Maintained by: Nickolay Kudasov <nickolay.kudasov@gmail.com>

  • Lottery factor: 3

Links

Installation

Tested Compilers

  1. 9.12.2
  2. 9.10.1
  3. 9.8.4
  4. 9.6.7
  5. 9.4.8
  6. 9.2.8
  7. 9.0.2
  8. 8.10.7
  9. 8.8.4
  10. 8.6.5

Package Flags

Use the -f option with cabal commands to enable flags

    use-text-show (off by default)

    Use text-show library for efficient ToHttpApiData implementations.

Readme

http-api-data

Build Status Hackage package Stackage LTS Stackage Nightly

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!