servant-http-streams: Automatic derivation of querying functions for servant

[ bsd3, library, servant, web ] [ Propose Tags ]

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]
Versions [faq] 0.16, 0.16.0.1
Change log CHANGELOG.md
Dependencies base (>=4.9 && <4.13), base-compat (>=0.10.5 && <0.11), bifunctors (>=5.5.3 && <5.6), bytestring (>=0.10.8.1 && <0.11), case-insensitive, containers (>=0.5.7.1 && <0.7), deepseq (>=1.4.2.0 && <1.5), exceptions (>=0.10.0 && <0.11), http-common (>=0.8.2.0 && <0.9), http-media (>=0.7.1.3 && <0.9), http-streams (>=0.8.6.1 && <0.9), http-types (>=0.12.2 && <0.13), io-streams (>=1.5.0.1 && <1.6), kan-extensions (==5.2.*), monad-control (>=1.0.2.3 && <1.1), mtl (>=2.2.2 && <2.3), semigroupoids (>=5.3.1 && <5.4), servant (==0.16.*), servant-client-core (>=0.16 && <0.16.1), text (>=1.2.3.0 && <1.3), time (>=1.6.0.1 && <1.9), 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 2019 Servant Contributors
Author Servant Contributors
Maintainer haskell-servant-maintainers@googlegroups.com
Revised Revision 2 made by phadej at Thu May 30 10:06:35 UTC 2019
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 phadej at Wed Feb 27 16:16:01 UTC 2019
Distributions NixOS:0.16.0.1, Stackage:0.16
Downloads 242 total (32 in the last 30 days)
Rating (no votes yet) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs available [build log]
Last success reported on 2019-02-27 [all 1 reports]

Modules

[Index] [Quick Jump]

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'.

Maintainer's Corner

For package maintainers and hackage trustees


Readme for servant-http-streams-0.16

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