servant-client-0.19: Automatic derivation of querying functions for servant
Safe Haskell None
Language Haskell2010

Servant.Client.Internal.HttpClient

Synopsis

Documentation

data ClientEnv 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

Constructors

ClientEnv

Fields

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 :: Manager and baseurl :: BaseUrl around:

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

newtype ClientM a Source #

ClientM is the monad in which client functions run. Contains the Manager and BaseUrl used for requests in the reader environment.

Instances

Instances details
Monad ClientM Source #
Instance details

Defined in Servant.Client.Internal.HttpClient

Functor ClientM Source #
Instance details

Defined in Servant.Client.Internal.HttpClient

Applicative ClientM Source #
Instance details

Defined in Servant.Client.Internal.HttpClient

MonadIO ClientM Source #
Instance details

Defined in Servant.Client.Internal.HttpClient

MonadThrow ClientM Source #
Instance details

Defined in Servant.Client.Internal.HttpClient

MonadCatch ClientM Source #
Instance details

Defined in Servant.Client.Internal.HttpClient

Alt ClientM Source #

Try clients in order, last error is preserved.

Instance details

Defined in Servant.Client.Internal.HttpClient

RunClient ClientM Source #
Instance details

Defined in Servant.Client.Internal.HttpClient

MonadReader ClientEnv ClientM Source #
Instance details

Defined in Servant.Client.Internal.HttpClient

MonadBase IO ClientM Source #
Instance details

Defined in Servant.Client.Internal.HttpClient

MonadBaseControl IO ClientM Source #
Instance details

Defined in Servant.Client.Internal.HttpClient

Associated Types

type StM ClientM a Source #

MonadError ClientError ClientM Source #
Instance details

Defined in Servant.Client.Internal.HttpClient

Generic ( ClientM a) Source #
Instance details

Defined in Servant.Client.Internal.HttpClient

Associated Types

type Rep ( ClientM a) :: Type -> Type Source #

type StM ClientM a Source #
Instance details

Defined in Servant.Client.Internal.HttpClient

type Rep ( ClientM a) Source #
Instance details

Defined in Servant.Client.Internal.HttpClient

type Rep ( ClientM a) = D1 (' MetaData "ClientM" "Servant.Client.Internal.HttpClient" "servant-client-0.19-7wRvsuXX2qvHY0EMO2okd8" ' True ) ( C1 (' MetaCons "ClientM" ' PrefixI ' True ) ( S1 (' MetaSel (' Just "unClientM") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 ( ReaderT ClientEnv ( ExceptT ClientError IO ) a))))

defaultMakeClientRequest :: BaseUrl -> Request -> Request Source #

Create a http-client Request from a servant Request The host , path and port fields are extracted from the BaseUrl otherwise the body, headers and query string are derived from the servant Request