| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Servant.Client.Internal.HttpClient
- data ClientEnv = ClientEnv {}
- mkClientEnv :: Manager -> BaseUrl -> ClientEnv
- 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 :: ClientM a -> ClientEnv -> IO (Either ServantError a)
- performRequest :: Request -> ClientM Response
- performStreamingRequest :: Request -> ClientM StreamingResponse
- clientResponseToResponse :: Response a -> GenResponse a
- requestToClientRequest :: BaseUrl -> Request -> Request
- catchConnectionError :: IO a -> IO (Either ServantError a)
Documentation
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 apihoistClient :: 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
Managerbaseurl :: 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
| Monad ClientM Source # | |
| Functor ClientM Source # | |
| Applicative ClientM Source # | |
| MonadIO ClientM Source # | |
| MonadThrow ClientM Source # | |
| MonadCatch ClientM Source # | |
| Alt ClientM Source # | Try clients in order, last error is preserved. |
| RunClient ClientM Source # | |
| MonadBase IO ClientM Source # | |
| MonadBaseControl IO ClientM Source # | |
| MonadReader ClientEnv ClientM Source # | |
| MonadError ServantError ClientM Source # | |
| Generic (ClientM a) Source # | |
| ClientLike (ClientM a) (ClientM a) Source # | |
| type StM ClientM a Source # | |
| type Rep (ClientM a) Source # | |
runClientM :: ClientM a -> ClientEnv -> IO (Either ServantError a) Source #
clientResponseToResponse :: Response a -> GenResponse a Source #
catchConnectionError :: IO a -> IO (Either ServantError a) Source #