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
|
2015-05-14 00:52:37 +02:00
|
|
|
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-05-14 00:52:37 +02:00
|
|
|
getAllBooks :: EitherT String IO [Book]
|
|
|
|
postNewBook :: Book -> EitherT String IO Book
|
2014-12-08 11:10:51 +01:00
|
|
|
-- 'client' allows you to produce operations to query an API from a client.
|
2015-05-14 00:52:37 +02:00
|
|
|
(getAllBooks :<|> postNewBook) = client myApi host
|
|
|
|
where host = BaseUrl Http "localhost" 8080
|
2015-04-20 15:38:26 +02:00
|
|
|
```
|