diff --git a/doc/tutorial/Client.lhs b/doc/tutorial/Client.lhs index 284d6e83..d409a437 100644 --- a/doc/tutorial/Client.lhs +++ b/doc/tutorial/Client.lhs @@ -62,6 +62,7 @@ Enough chitchat, let's see an example. Consider the following API type from the type API = "position" :> Capture "x" Int :> Capture "y" Int :> Get '[JSON] Position :<|> "hello" :> QueryParam "name" String :> Get '[JSON] HelloMessage :<|> "marketing" :> ReqBody '[JSON] ClientInfo :> Post '[JSON] Email + :<|> EmptyAPI ``` What we are going to get with **servant-client** here is three functions, one to query each endpoint: @@ -76,6 +77,8 @@ hello :: Maybe String -- ^ an optional value for "name" marketing :: ClientInfo -- ^ value for the request body -> ClientM Email + +emptyClient :: EmptyAPIClient ``` Each function makes available as an argument any value that the response may @@ -88,7 +91,7 @@ the function `client`. It takes one argument: api :: Proxy API api = Proxy -position :<|> hello :<|> marketing = client api +position :<|> hello :<|> marketing :<|> emptyClient = client api ``` `client api` returns client functions for our _entire_ API, combined with `:<|>`, which we can pattern match on as above. You could say `client` "calculates" the correct type and number of client functions for the API type it is given (via a `Proxy`), as well as their implementations. diff --git a/servant-client/src/Servant/Client.hs b/servant-client/src/Servant/Client.hs index d6084edf..cd68adc9 100644 --- a/servant-client/src/Servant/Client.hs +++ b/servant-client/src/Servant/Client.hs @@ -24,6 +24,7 @@ module Servant.Client , ClientEnv (ClientEnv) , mkAuthenticateReq , ServantError(..) + , EmptyAPIClient(..) , module Servant.Common.BaseUrl ) where @@ -88,6 +89,13 @@ instance (HasClient a, HasClient b) => HasClient (a :<|> b) where clientWithRoute (Proxy :: Proxy a) req :<|> clientWithRoute (Proxy :: Proxy b) req +-- | TODO docs +data EmptyAPIClient = EmptyAPIClient + +instance HasClient EmptyAPI where + type Client EmptyAPI = EmptyAPIClient + clientWithRoute Proxy _ = EmptyAPIClient + -- | If you use a 'Capture' in one of your endpoints in your API, -- the corresponding querying function will automatically take -- an additional argument of the type specified by your 'Capture'.