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