servant/servant-http-streams
Gaël Deest 613dcf9ed5 Basic GitHub actions-based CI
- Setup a basic CI based on GitHub actions, with a somewhat limited build matrix.
- Disable cookbook/testing, because servant-quickcheck doesn't build anymore.
- Disable servant-docs on Cabal build, because of some test failures
  - The order of some JSON fields seems to be reversed in the output, need investigation.
- Fix test failures in servant-http-streams when `localhost` points to an IPv6 address rather than 127.0.0.1.
2021-03-17 23:22:20 +01:00
..
src/Servant union verbs (#1314) 2020-10-31 20:45:46 +01:00
test Basic GitHub actions-based CI 2021-03-17 23:22:20 +01:00
CHANGELOG.md Prepare 0.18.2 release (#1364) 2020-11-22 17:51:32 +03: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 Allow bytestring-0.11 (#1386) 2020-12-16 11:04:49 +01: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 ()