HORIZON HASKELLDocslts/ghc-9.14.x3e2d5682026-10-11Search names, modules, packages, or :: a typeCtrl K

GHC 9.14.1 · lts/ghc-9.14.x · 3e2d568 · 2026-10-11

Moduleservant-client-0.20.3.0Haskell2010

Servant.Client.Internal.HttpClient

  • 4 types
  • 9 values
datadata ClientEnv
#

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

Instances2MonadReader
valueclient :: HasClient ClientM api => Proxy api -> Client ClientM api
#

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
valuehoistClient
  1. :: HasClient ClientM api
  2. => Proxy api
  3. -> forall a. m a -> n a
  4. -> Client m api
  5. -> Client n api
#

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
newtypenewtype ClientM a
#

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

Instances16Monad, Functor, Applicative, MonadIO, MonadCatch, MonadMask, …

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

Note that Applicative dependency is not really needed for this function implementation. But in the past the return type was wrapped into IO without a necessity breaking the API backward-compatibility. In order to not break the API again it was changed to Applicative so that you can just use something like Data.Functor.Identity without a need to involve IO but still keeping it compatible with the code written when it was typed as IO.