servant/servant-http-streams
Erik Aker 68014463d9 Rewrite client concatQueryString for client requests and pull extraneous data type for spec
Remove symbol from QueryParamForm type args

Remove the data instance for QueryParamForm in HasDocs
2019-10-03 20:28:00 -07:00
..
src/Servant Rename ServantError to ClientError, ServantErr to ServerError 2019-02-18 22:51:09 +02:00
test Rewrite client concatQueryString for client requests and pull extraneous data type for spec 2019-10-03 20:28:00 -07:00
CHANGELOG.md Copy changelog entries to other packages 2019-02-21 13:31:24 +02:00
LICENSE Add servant-http-streams 2019-02-06 12:15:30 +02:00
README.lhs Add servant-http-streams 2019-02-06 12:15:30 +02:00
README.md Add servant-http-streams 2019-02-06 12:15:30 +02:00
servant-http-streams.cabal Relax bounds for ghc-8.8 2019-09-29 00:43:53 +03:00
Setup.hs Add servant-http-streams 2019-02-06 12:15:30 +02:00

servant-client

servant

This library lets you automatically derive Haskell functions that let you query each endpoint of a servant webservice.

Example

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}

import Data.Proxy
import Data.Text
import Servant.API
import Servant.HttpStreams


type Book = Text

type MyApi = "books" :> Get '[JSON] [Book] -- GET /books
        :<|> "books" :> ReqBody '[JSON] Book :> Post '[JSON] Book -- POST /books

myApi :: Proxy MyApi
myApi = Proxy

-- 'client' allows you to produce operations to query an API from a client.
postNewBook :: Book -> ClientM Book
getAllBooks :: ClientM [Book]
(getAllBooks :<|> postNewBook) = client myApi

-- the IOException happens already in withClientEnvIO
main' :: IO ()
main' = do
    let burl = BaseUrl Http "localhost" 8081 ""
    withClientEnvIO burl $ \env -> do
        res <- runClientM getAllBooks env
        case res of
            Left err -> putStrLn $ "Error: " ++ show err
            Right books -> print books

main :: IO ()
main = return ()