servant-http-streams

Automatic derivation of querying functions for servant

http://docs.servant.dev/

Version on this page:0.18.3
LTS Haskell 22.39:0.20.2
Stackage Nightly 2024-10-31:0.20.2
Latest on Hackage:0.20.2

See all snapshots servant-http-streams appears in

BSD-3-Clause licensed by Servant Contributors
Maintained by [email protected]
This version can be pinned in stack with:servant-http-streams-0.18.3@sha256:169f53485aac8596e83afbad73fb7b631d735e4c4d0a335a027883e4c50e6a76,4366

Module documentation for 0.18.3

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 ()

Changes

The latest version of this document is on GitHub. Changelog for servant package contains significant entries for all core packages.

0.18.3

Other changes

  • Support GHC-9.0.1.
  • Fix test suite running in CI.
  • Bump bytestring and hspec dependencies.

0.18.2

Significant changes

  • Support servant-client-core 0.18.2.

0.18.1

Significant changes

  • Union verbs

Other changes

  • Bump “tested-with” ghc versions

0.18

Significant changes

  • Support for ghc8.8 (#1318, #1326, #1327)

0.17

Significant changes

  • Add NoContentVerb #1028 #1219 #1228

    The NoContent API endpoints should now use NoContentVerb combinator. The API type changes are usually of the kind

    - :<|> PostNoContent '[JSON] NoContent
    + :<|> PostNoContent
    

    i.e. one doesn’t need to specify the content-type anymore. There is no content.

  • Capture can be Lenient #1155 #1156

    You can specify a lenient capture as

    :<|> "capture-lenient"  :> Capture' '[Lenient] "foo" Int :> GET
    

    which will make the capture always succeed. Handlers will be of the type Either String CapturedType, where Left err represents the possible parse failure.

Other changes

  • servant-client servant-client-core servant-http-streams Fix Verb with headers checking content type differently #1200 #1204

    For Verbs with response Headers, the implementation didn’t check for the content-type of the response. Now it does.

  • servant-client servant-http-streams HasClient instance for Stream with Headers #1170 #1197

  • servant-client Redact the authorization header in Show and exceptions #1238

0.16.0.1

  • Allow base-compat-0.11

0.16

  • Initial release