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 [Book] -- GET /books
|
|
|
|
:<|> "books" :> ReqBody Book :> Post Book -- POST /books
|
|
|
|
|
|
|
|
myApi :: Proxy MyApi
|
|
|
|
myApi = Proxy
|
|
|
|
|
|
|
|
getAllBooks :: BaseUrl -> EitherT String IO [Book]
|
|
|
|
postNewBook :: Book -> BaseUrl -> EitherT String IO Book
|
|
|
|
-- 'client' allows you to produce operations to query an API from a client.
|
|
|
|
(getAllBooks :<|> postNewBook) = client myApi
|
2015-04-20 15:38:26 +02:00
|
|
|
```
|