Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- newtype ClientM a = ClientM {}
- client :: HasClient ClientM api => Proxy api -> Client ClientM api
- hoistClient :: HasClient ClientM api => Proxy api -> (forall a. m a -> n a) -> Client m api -> Client n api
- withClientM :: ClientM a -> ClientEnv -> (Either ClientError a -> IO b) -> IO b
- runClientM :: NFData a => ClientM a -> ClientEnv -> IO (Either ClientError a)
- performRequest :: Request -> ClientM Response
- performWithStreamingRequest :: Request -> (StreamingResponse -> IO a) -> ClientM a
- data ClientEnv = ClientEnv {}
- mkClientEnv :: Manager -> BaseUrl -> ClientEnv
- clientResponseToResponse :: (a -> b) -> Response a -> ResponseF b
- defaultMakeClientRequest :: BaseUrl -> Request -> Request
- catchConnectionError :: IO a -> IO (Either ClientError a)
Documentation
ClientM
is the monad in which client functions run. Contains the
Manager
and BaseUrl
used for requests in the reader environment.
Instances
client :: HasClient ClientM api => Proxy api -> Client ClientM api Source #
Generates a set of client functions for an API.
Example:
type API = Capture "no" Int :> Get '[JSON] Int :<|> Get '[JSON] [Bool] api :: Proxy API api = Proxy getInt :: Int -> ClientM Int getBools :: ClientM [Bool] getInt :<|> getBools = client api
hoistClient :: HasClient ClientM api => Proxy api -> (forall a. m a -> n a) -> Client m api -> Client n api Source #
Change the monad the client functions live in, by supplying a conversion function (a natural transformation to be precise).
For example, assuming you have some manager ::
and
Manager
baseurl ::
around:BaseUrl
type API = Get '[JSON] Int :<|> Capture "n" Int :> Post '[JSON] Int api :: Proxy API api = Proxy getInt :: IO Int postInt :: Int -> IO Int getInt :<|> postInt = hoistClient api (flip runClientM cenv) (client api) where cenv = mkClientEnv manager baseurl
withClientM :: ClientM a -> ClientEnv -> (Either ClientError a -> IO b) -> IO b Source #
runClientM :: NFData a => ClientM a -> ClientEnv -> IO (Either ClientError a) Source #
A runClientM
variant for streaming client.
It allows using this module's ClientM
in a direct style.
The NFData
constraint however prevents using this function with genuine
streaming response types (SourceT
, Conduit
, pipes Proxy
or Machine
).
For those you have to use withClientM
.
Note: we force
the result, so the likehood of accidentally leaking a
connection is smaller. Use with care.
performWithStreamingRequest :: Request -> (StreamingResponse -> IO a) -> ClientM a Source #
The environment in which a request is run.
The baseUrl
and makeClientRequest
function are used to create a http-client
request.
Cookies are then added to that request if a CookieJar
is set on the environment.
Finally the request is executed with the manager
.
The makeClientRequest
function can be used to modify the request to execute and set values which
are not specified on a servant
Request
like responseTimeout
or redirectCount
ClientEnv | |
|
Instances
MonadReader ClientEnv ClientM Source # | |
MonadReader ClientEnv ClientM Source # | |
clientResponseToResponse :: (a -> b) -> Response a -> ResponseF b Source #
catchConnectionError :: IO a -> IO (Either ClientError a) Source #