| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Servant.Client.Internal.HttpClient
Synopsis
- 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 ClientError a)
- performRequest :: Request -> ClientM Response
- mkFailureResponse :: BaseUrl -> Request -> ResponseF ByteString -> ClientError
- clientResponseToResponse :: (a -> b) -> Response a -> ResponseF b
- requestToClientRequest :: BaseUrl -> Request -> Request
- catchConnectionError :: IO a -> IO (Either ClientError a)
Documentation
The environment in which a request is run.
Constructors
| ClientEnv | |
mkClientEnv :: Manager -> BaseUrl -> 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 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 # | |
| MonadCatch ClientM Source # | |
Defined in Servant.Client.Internal.HttpClient | |
| MonadThrow ClientM Source # | |
Defined in Servant.Client.Internal.HttpClient | |
| MonadIO ClientM Source # | |
Defined in Servant.Client.Internal.HttpClient | |
| Alt ClientM Source # | Try clients in order, last error is preserved. |
| RunClient ClientM Source # | |
Defined in Servant.Client.Internal.HttpClient | |
| MonadBase IO ClientM Source # | |
Defined in Servant.Client.Internal.HttpClient | |
| MonadError ClientError ClientM Source # | |
Defined in Servant.Client.Internal.HttpClient Methods throwError :: ClientError -> ClientM a catchError :: ClientM a -> (ClientError -> ClientM a) -> ClientM a | |
| MonadReader ClientEnv ClientM Source # | |
| MonadBaseControl IO ClientM Source # | |
Defined in Servant.Client.Internal.HttpClient Associated Types type StM ClientM a | |
| Generic (ClientM a) Source # | |
| type StM ClientM a Source # | |
Defined in Servant.Client.Internal.HttpClient type StM ClientM a = Either ClientError a | |
| type Rep (ClientM a) Source # | |
Defined in Servant.Client.Internal.HttpClient type Rep (ClientM a) = D1 ('MetaData "ClientM" "Servant.Client.Internal.HttpClient" "servant-client-0.16.0.1-AzejWy1MYIq3Uz8VyB8TYA" 'True) (C1 ('MetaCons "ClientM" 'PrefixI 'True) (S1 ('MetaSel ('Just "unClientM") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (ReaderT ClientEnv (ExceptT ClientError IO) a)))) | |
runClientM :: ClientM a -> ClientEnv -> IO (Either ClientError a) Source #
performRequest :: Request -> ClientM Response Source #
mkFailureResponse :: BaseUrl -> Request -> ResponseF ByteString -> ClientError Source #
clientResponseToResponse :: (a -> b) -> Response a -> ResponseF b Source #
requestToClientRequest :: BaseUrl -> Request -> Request Source #
catchConnectionError :: IO a -> IO (Either ClientError a) Source #