Copyright | (c) 2020 Alex Chapman |
---|---|
License | BSD3 |
Maintainer | alex@farfromthere.net |
Stability | experimental |
Portability | GHC |
Safe Haskell | None |
Language | Haskell2010 |
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
- data ServantClient m a
- runClient' :: forall r o. (MemberWithError ServantClient r, NFData o) => ClientM o -> Sem r (Either ClientError o)
- runClient :: (Members '[ServantClient, Error ClientError] r, NFData o) => ClientM o -> Sem r o
- data ServantClientStreaming m a
- runClientStreaming :: forall r o. MemberWithError ServantClientStreaming r => ClientM o -> Sem r o
- runServantClientUrl :: Member (Embed IO) r => BaseUrl -> Sem (ServantClient ': r) a -> Sem r a
- runServantClient :: Member (Embed IO) r => String -> Sem (ServantClient ': r) a -> Sem r a
- runServantClientStreamingUrl :: Members '[Cont ref, Embed IO, Error ClientError] r => BaseUrl -> Sem (ServantClientStreaming ': r) a -> Sem r a
- runServantClientStreaming :: Members '[Cont ref, Embed IO, Error ClientError] r => String -> Sem (ServantClientStreaming ': r) a -> Sem r a
- data ClientError
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' :: forall r o. (MemberWithError ServantClient r, NFData o) => ClientM o -> Sem r (Either ClientError o) Source #
runClient :: (Members '[ServantClient, Error ClientError] r, NFData o) => ClientM o -> Sem r o Source #
Streaming
data ServantClientStreaming m a Source #
The ServantClientStreaming
effect is just like the ServantClient
effect,
but allows streaming connections.
runClientStreaming :: forall r o. MemberWithError ServantClientStreaming r => ClientM o -> Sem r o Source #
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.