@@ -62,6 +62,7 @@ Enough chitchat, let's see an example. Consider the following API type from the
62type API = "position" :> Capture "x" Int :> Capture "y" Int :> Get '[JSON] Position
62type API = "position" :> Capture "x" Int :> Capture "y" Int :> Get '[JSON] Position
63 :<|> "hello" :> QueryParam "name" String :> Get '[JSON] HelloMessage
63 :<|> "hello" :> QueryParam "name" String :> Get '[JSON] HelloMessage
64 :<|> "marketing" :> ReqBody '[JSON] ClientInfo :> Post '[JSON] Email
64 :<|> "marketing" :> ReqBody '[JSON] ClientInfo :> Post '[JSON] Email
67What we are going to get with **servant-client** here is three functions, one to query each endpoint:
68What 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"
77marketing :: ClientInfo -- ^ value for the request body
78marketing :: ClientInfo -- ^ value for the request body
78 -> ClientM Email
79 -> ClientM Email
81+emptyClient :: EmptyAPIClient
81Each function makes available as an argument any value that the response may
84Each function makes available as an argument any value that the response may
@@ -88,7 +91,7 @@ the function `client`. It takes one argument:
88api :: Proxy API
91api :: Proxy API
89api = Proxy
92api = Proxy
91−position :<|> hello :<|> marketing = client api
94+position :<|> hello :<|> marketing :<|> emptyClient = client api
94`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.
97`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.