Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data ClientEnv = ClientEnv {}
- mkClientEnv :: BaseUrl -> Connection -> ClientEnv
- withClientEnvIO :: BaseUrl -> (ClientEnv -> IO r) -> IO r
- 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
- newtype ClientM a = ClientM {}
- runClientM :: NFData a => ClientM a -> ClientEnv -> IO (Either ClientError a)
- withClientM :: ClientM a -> ClientEnv -> (Either ClientError a -> IO b) -> IO b
- performRequest :: Maybe [Status] -> Request -> ClientM Response
- performWithStreamingRequest :: Request -> (StreamingResponse -> IO a) -> ClientM a
- mkFailureResponse :: BaseUrl -> Request -> ResponseF ByteString -> ClientError
- clientResponseToResponse :: Response -> body -> ResponseF body
- requestToClientRequest :: BaseUrl -> Request -> (Request, OutputStream Builder -> IO ())
- catchConnectionError :: IO a -> IO (Either ClientError a)
- fromInputStream :: InputStream b -> SourceT IO b
- toOutputStream :: SourceT IO ByteString -> OutputStream Builder -> IO ()
Documentation
The environment in which a request is run.
ClientEnv
carries an open connection. See withClientEnvIO
.
mkClientEnv :: BaseUrl -> Connection -> ClientEnv Source #
ClientEnv
smart constructor.
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
ClientM
is the monad in which client functions run. Contains the
Manager
and BaseUrl
used for requests in the reader environment.
Instances
runClientM :: NFData a => ClientM a -> ClientEnv -> IO (Either ClientError a) Source #
withClientM :: ClientM a -> ClientEnv -> (Either ClientError a -> IO b) -> IO b Source #
performWithStreamingRequest :: Request -> (StreamingResponse -> IO a) -> ClientM a Source #
mkFailureResponse :: BaseUrl -> Request -> ResponseF ByteString -> ClientError Source #
clientResponseToResponse :: Response -> body -> ResponseF body Source #
requestToClientRequest :: BaseUrl -> Request -> (Request, OutputStream Builder -> IO ()) Source #
catchConnectionError :: IO a -> IO (Either ClientError a) Source #
fromInputStream :: InputStream b -> SourceT IO b Source #
toOutputStream :: SourceT IO ByteString -> OutputStream Builder -> IO () Source #