servant/servant-client/README.md

22 lines
683 B
Markdown
Raw Normal View History

2014-12-08 11:10:51 +01:00
# servant-client
![servant](https://raw.githubusercontent.com/haskell-servant/servant/master/servant.png)
2015-02-06 09:34:59 +01:00
This library lets you automatically derive Haskell functions that let you query each endpoint of a *servant* webservice.
2014-12-08 11:10:51 +01:00
## Example
``` haskell
type MyApi = "books" :> Get '[JSON] [Book] -- GET /books
:<|> "books" :> ReqBody Book :> Post '[JSON] Book -- POST /books
2014-12-08 11:10:51 +01:00
myApi :: Proxy MyApi
myApi = Proxy
2015-09-12 14:11:24 +02:00
getAllBooks :: ExceptT String IO [Book]
postNewBook :: Book -> ExceptT String IO Book
2014-12-08 11:10:51 +01:00
-- 'client' allows you to produce operations to query an API from a client.
(getAllBooks :<|> postNewBook) = client myApi host
where host = BaseUrl Http "localhost" 8080
2015-04-20 15:38:26 +02:00
```