git.iko.soy/typeable/http-api-data
on v0.3.2 help sign in
57 lines 1.4 kB history raw
1# http-api-data
3[![Build Status](https://secure.travis-ci.org/fizruk/http-api-data.png?branch=master)](http://travis-ci.org/fizruk/http-api-data)
4[![Hackage package](http://img.shields.io/hackage/v/http-api-data.svg)](http://hackage.haskell.org/package/http-api-data)
5[![Stackage LTS](http://stackage.org/package/http-api-data/badge/lts)](http://stackage.org/lts/package/http-api-data)
6[![Stackage Nightly](http://stackage.org/package/http-api-data/badge/nightly)](http://stackage.org/nightly/package/http-api-data)
8This package defines typeclasses used for converting Haskell data types to and from HTTP API data.
10### Examples
12Booleans:
14```
15>>> toUrlPiece True
16"true"
17>>> parseUrlPiece "false" :: Either Text Bool
18Right False
19>>> parseUrlPieces ["true", "false", "undefined"] :: Either Text [Bool]
20Left "could not parse: `undefined'"
21```
23Numbers:
25```
26>>> toQueryParam 45.2
27"45.2"
28>>> parseQueryParam "452" :: Either Text Int
29Right 452
30>>> toQueryParams [1..5]
31["1","2","3","4","5"]
32>>> parseQueryParams ["127", "255"] :: Either Text [Int8]
33Left "out of bounds: `255' (should be between -128 and 127)"
34```
36Strings:
38```
39>>> toHeader "hello"
40"hello"
41>>> parseHeader "world" :: Either Text String
42Right "world"
43```
45Calendar day:
47```
48>>> toQueryParam (fromGregorian 2015 10 03)
49"2015-10-03"
50>>> toGregorian <$> parseQueryParam "2016-12-01"
51Right (2016,12,1)
52```
54## Contributing
56Contributions and bug reports are welcome!