servant/servant-http-streams
Matthieu Coudron 73c87bc2bc
bumped cabal-version field (#1498)
* bumped cabal-version field

Cabal supports two types of licenses, native and SPDX, which can be seen here hackage.haskell.org/package/Cabal-3.6.2.0/docs/Distribution-Types-PackageDescription.html#v:licenseRaw

Several packages use BSD-3-Clause as a license, in conjonction with cabal-version: >=1.10 which cabal parses as Right (UnknownLicense "BSD-3").
If I change teh cabal-version to cabal-version: 2.2 , cabal correctly identifdies the license License (ELicense (ELicenseId BSD_3_Clause)).

* changed license from cabal to spdx format

aka BSD3 -> BSD-3-Clause: next cabal may deprecate the old format
2022-01-04 22:06:23 +01:00
..
src/Servant Derive HasClient good response status from Verb status (#1469) 2021-12-09 10:09:18 +01:00
test unsupporting GHC < 8.6.5, removing unecessary imports 2021-10-02 13:13:24 +02:00
CHANGELOG.md Prepare 0.18.3 release (#1430) 2021-06-24 00:38:46 +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 bumped cabal-version field (#1498) 2022-01-04 22:06:23 +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 ()