servant-polysemy-0.1.2: Utilities for using servant in a polysemy stack
Copyright(c) 2020 Alex Chapman
LicenseBSD3
Maintaineralex@farfromthere.net
Stabilityexperimental
PortabilityGHC
Safe HaskellNone
LanguageHaskell2010

Servant.Polysemy.Client

Description

This module allows you to act as a client of a Servant API, within a Polysemy Sem. Use the servant-client package to generate your clients, which return in the ClientM monad. You can then use runClient (or runClientStreaming) to run your client in Sem, and runServantClient (or runServantClientStreaming) to interpret the effect.

See example/Client.hs for a simple example that can interact with the example servers in the same directory.

Synopsis

Effects

Non-Streaming

data ServantClient m a Source #

The ServantClient effect allows you to run a ClientM as automatically generated for your API by the servant-client package.

runClient :: (Members '[ServantClient, Error ClientError] r, NFData o) => ClientM o -> Sem r o Source #

Run this ClientM in the Sem monad.

Streaming

data ServantClientStreaming m a Source #

The ServantClientStreaming effect is just like the ServantClient effect, but allows streaming connections.

Interpreters

Non-Streaming

runServantClientUrl :: Member (Embed IO) r => BaseUrl -> Sem (ServantClient ': r) a -> Sem r a Source #

Interpret the ServantClient effect by running any calls to RunClient' against the given BaseUrl.

runServantClient :: Member (Embed IO) r => String -> Sem (ServantClient ': r) a -> Sem r a Source #

Parse the given string as a URL and then behave as runServantClientUrl does.

Streaming

runServantClientStreamingUrl :: Members '[Cont ref, Embed IO, Error ClientError] r => BaseUrl -> Sem (ServantClientStreaming ': r) a -> Sem r a Source #

Interpret the ServantClientStreaming effect by running any calls to RunClientStreaming against the given URL. Note that this adds a Cont effect, which you can interpret using runContM, probably just before your call to runM.

runServantClientStreaming :: Members '[Cont ref, Embed IO, Error ClientError] r => String -> Sem (ServantClientStreaming ': r) a -> Sem r a Source #

Parse the given string as a URL and then behave as runServantClientStreamingUrl.

Re-exported from Servant

data ClientError #

A type representing possible errors in a request

Note that this type substantially changed in 0.12.

Instances

Instances details
Eq ClientError 
Instance details

Defined in Servant.Client.Core.ClientError

Show ClientError 
Instance details

Defined in Servant.Client.Core.ClientError

Generic ClientError 
Instance details

Defined in Servant.Client.Core.ClientError

Associated Types

type Rep ClientError :: Type -> Type #

Exception ClientError 
Instance details

Defined in Servant.Client.Core.ClientError

NFData ClientError

Note: an exception in ConnectionError might not be evaluated fully, We only rnf its showed value.

Instance details

Defined in Servant.Client.Core.ClientError

Methods

rnf :: ClientError -> () #

MonadError ClientError ClientM 
Instance details

Defined in Servant.Client.Internal.HttpClient.Streaming

MonadError ClientError ClientM 
Instance details

Defined in Servant.Client.Internal.HttpClient

type Rep ClientError 
Instance details

Defined in Servant.Client.Core.ClientError