servant-client: Automatic derivation of querying functions for servant

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

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

See the client section of the tutorial.

CHANGELOG


[Skip to Readme]

Properties

Versions 0.2, 0.2.1, 0.2.2, 0.4.0, 0.4.1, 0.4.2, 0.4.3, 0.4.3.1, 0.4.4, 0.4.4.2, 0.4.4.3, 0.4.4.4, 0.4.4.5, 0.4.4.6, 0.4.4.7, 0.5, 0.6, 0.6.1, 0.7, 0.7.1, 0.8, 0.8.1, 0.9, 0.9.0.1, 0.9.1, 0.9.1.1, 0.10, 0.11, 0.12, 0.12.0.1, 0.13, 0.13.0.1, 0.14, 0.15, 0.16, 0.16.0.1, 0.17, 0.18, 0.18.1, 0.18.1, 0.18.2, 0.18.3, 0.19, 0.20
Change log CHANGELOG.md
Dependencies base (>=4.9 && <4.15), base-compat (>=0.10.5 && <0.12), bifunctors (>=5.5.3 && <5.6), bytestring (>=0.10.8.1 && <0.11), containers (>=0.5.7.1 && <0.7), deepseq (>=1.4.2.0 && <1.5), exceptions (>=0.10.0 && <0.11), http-client (>=0.5.13.1 && <0.7), http-media (>=0.7.1.3 && <0.9), http-types (>=0.12.2 && <0.13), kan-extensions (>=5.2 && <5.3), monad-control (>=1.0.2.3 && <1.1), mtl (>=2.2.2 && <2.3), semigroupoids (>=5.3.1 && <5.4), servant (>=0.18 && <0.19), servant-client-core (>=0.18 && <0.18.2), stm (>=2.4.5.1 && <2.6), text (>=1.2.3.0 && <1.3), time (>=1.6.0.1 && <1.10), transformers (>=0.5.2.0 && <0.6), transformers-base (>=0.4.5.2 && <0.5), transformers-compat (>=0.6.2 && <0.7) [details]
License BSD-3-Clause
Copyright 2014-2016 Zalora South East Asia Pte Ltd, 2016-2019 Servant Contributors
Author Servant Contributors
Maintainer haskell-servant-maintainers@googlegroups.com
Category Servant, Web
Home page http://docs.servant.dev/
Bug tracker http://github.com/haskell-servant/servant/issues
Source repo head: git clone http://github.com/haskell-servant/servant.git
Uploaded by maksbotan at 2020-11-04T19:36:51Z

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for servant-client-0.18.1

[back to package description]

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 Network.HTTP.Client (newManager, defaultManagerSettings)
import Servant.API
import Servant.Client


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


main :: IO ()
main = do
  manager' <- newManager defaultManagerSettings
  res <- runClientM getAllBooks (mkClientEnv manager' (BaseUrl Http "localhost" 8081 ""))
  case res of
    Left err -> putStrLn $ "Error: " ++ show err
    Right books -> print books