Safe Haskell | None |
---|---|
Language | Haskell2010 |
Servant.Client
Description
This module provides client
which can automatically generate
querying functions for each endpoint just from the type representing your
API.
Synopsis
- client :: HasClient ClientM api => Proxy api -> Client ClientM api
- data ClientM a
- runClientM :: ClientM a -> ClientEnv -> IO (Either ClientError a)
- data ClientEnv = ClientEnv {}
- mkClientEnv :: Manager -> BaseUrl -> ClientEnv
- hoistClient :: HasClient ClientM api => Proxy api -> (forall a. m a -> n a) -> Client m api -> Client n api
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 api
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 #
The environment in which a request is run.
Constructors
ClientEnv | |
mkClientEnv :: Manager -> BaseUrl -> ClientEnv Source #
ClientEnv
smart constructor.
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