servant-client: automatical derivation of querying functions for servant webservices

[ bsd3, library, servant, web ] [ Propose Tags ] [ Report a vulnerability ]

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]

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Versions [RSS] 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.2, 0.18.3, 0.19, 0.20, 0.20.1, 0.20.2 (info)
Change log CHANGELOG.md
Dependencies base (>=4.7 && <4.13), base-compat (>=0.10.1 && <0.11), bytestring (>=0.10.4.0 && <0.11), containers (>=0.5.5.1 && <0.7), exceptions (>=0.10.0 && <0.11), http-client (>=0.5.12 && <0.6), http-media (>=0.7.1.2 && <0.8), http-types (>=0.12.1 && <0.13), monad-control (>=1.0.2.3 && <1.1), mtl (>=2.1 && <2.3), semigroupoids (>=5.2.2 && <5.4), semigroups (>=0.18.4 && <0.19), servant-client-core (>=0.14 && <0.15), stm (>=2.4.5.0 && <2.6), text (>=1.2.3.0 && <1.3), time (>=1.4.2 && <1.9), transformers (>=0.3.0.0 && <0.6), transformers-base (>=0.4.5.2 && <0.5), transformers-compat (>=0.6.2 && <0.7) [details]
Tested with ghc ==7.8.4, ghc ==7.10.3, ghc ==8.0.2, ghc ==8.2.2, ghc ==8.4.4, ghc ==8.6.1
License BSD-3-Clause
Copyright 2014-2016 Zalora South East Asia Pte Ltd, 2016-2017 Servant Contributors
Author Servant Contributors
Maintainer haskell-servant-maintainers@googlegroups.com
Revised Revision 3 made by phadej at 2018-10-24T11:23:59Z
Category Servant, Web
Home page http://haskell-servant.readthedocs.org/
Bug tracker http://github.com/haskell-servant/servant/issues
Source repo head: git clone http://github.com/haskell-servant/servant.git
Uploaded by phadej at 2018-06-19T09:37:56Z
Distributions Arch:0.20, Debian:0.16.0.1, Fedora:0.19, LTSHaskell:0.20.2, NixOS:0.20.2, Stackage:0.20.2, openSUSE:0.20.2
Reverse Dependencies 129 direct, 32 indirect [details]
Downloads 53804 total (278 in the last 30 days)
Rating 2.25 (votes: 2) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2018-06-19 [all 1 reports]

Readme for servant-client-0.14

[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