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 ()
:<|> "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-clientservant-client-coreservant-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-clientservant-http-streamsHasClient instance for Stream with Headers#1170#1197
servant-client Redact the authorization header in Show and exceptions #1238