@@ -24,14 +24,37 @@ template <class Tag>
2424struct basic_response ;
2525
2626template <class Tag ,unsigned version_major,unsigned version_minor>
27- struct basic_client_facade {
28-
27+ class basic_client_facade {
28+ typedef basic_client_impl<Tag, version_major, version_minor> pimpl_type;
29+ public:
30+ /* *
31+ * The type to use for strings associated with this client. Typically resolves
32+ * to `std::string`.
33+ */
2934typedef typename string<Tag>::type string_type;
35+
36+ /* * The request type. This models the HTTP Request concept.*/
3037typedef basic_request<Tag> request;
38+
39+ /* * The response type. This models the HTTP Response concept.*/
3140typedef basic_response<Tag> response;
32- typedef basic_client_impl<Tag, version_major, version_minor> pimpl_type;
41+
42+ /* *
43+ * This callback is invoked with a range representing part of the response's
44+ * body as it comes in. In case of errors, the second argument is an error
45+ * code.
46+ */
3347typedef function<void (iterator_range<char const *>const &,
3448 system::error_codeconst &)> body_callback_function_type;
49+
50+ /* *
51+ * Functions that model this signature will be used to generate part of the
52+ * body while the request is being performed. This allows users to provide a
53+ * generator function that will generate the body of the request piece-wise.
54+ *
55+ * Implementations should return `true` if there is more to the body of the
56+ * request, and `false` otherwise.
57+ */
3558typedef function<bool (string_type&)> body_generator_function_type;
3659
3760explicit basic_client_facade (client_options<Tag>const & options) {
@@ -40,19 +63,49 @@ struct basic_client_facade {
4063
4164~basic_client_facade () { pimpl->wait_complete (); }
4265
66+ /* *
67+ * Perform a HEAD request.
68+ */
4369 responsehead (requestconst & request) {
4470return pimpl->request_skeleton (request," HEAD" ,false ,
4571body_callback_function_type (),
4672body_generator_function_type ());
4773 }
4874
75+ /* *
76+ * Perform a GET request.
77+ *
78+ * @param[in] request The request object including the URI and headers.
79+ * @param[in] body_handler If provided, a callback invoked for parts of the
80+ * response's body.
81+ * @returns A response object.
82+ * @throw std::exception May throw exceptions on errors, derived from
83+ * `std::exception`.
84+ */
4985 responseget (requestconst & request,
5086 body_callback_function_type body_handler =
5187body_callback_function_type ()) {
5288return pimpl->request_skeleton (request," GET" ,true , body_handler,
5389body_generator_function_type ());
5490 }
5591
92+ /* *
93+ * Perform a POST request.
94+ *
95+ * @param[in] request A copy of the request object including the URI and
96+ * headers.
97+ * @param[in] body The whole contents of the body. If provided, this overrides
98+ * the body in the `request`.
99+ * @param[in] content_type The content type for the request. This overrides
100+ * the content type in the `request`.
101+ * @param[in] body_handler The callback invoked for parts of the response body
102+ * as they come in.
103+ * @param[in] body_generator If provided, is invoked to generate parts of the
104+ * request's body as it is being sent.
105+ * @returns A response object.
106+ * @throws std::exception May throw exceptions on errors, derived from
107+ * `std::exception`.
108+ */
56109 responsepost (request request, string_typeconst & body = string_type(),
57110 string_typeconst & content_type = string_type(),
58111 body_callback_function_type body_handler =
@@ -82,28 +135,82 @@ struct basic_client_facade {
82135 body_generator);
83136 }
84137
138+ /* *
139+ * Perform a POST request.
140+ *
141+ * @param[in] request The request including the URI and headers.
142+ * @param[in] body_generator The function to call to generate part of the body
143+ * while the request is being performed.
144+ * @param[in] callback If provided, the function to call for parts of the
145+ * response's body as they come in.
146+ * @returns A response object.
147+ * @throws std::exception May throw exceptions derived from std::exception in
148+ * case of errors.
149+ */
85150 responsepost (requestconst & request,
86151 body_generator_function_type body_generator,
87- body_callback_function_typecallback =
88- body_generator_function_type ()) {
89- return pimpl->request_skeleton (request," POST" ,true ,callback ,
90- body_generator);
152+ body_callback_function_typebody_handler =
153+ body_callback_function_type ()) {
154+ return pimpl->request_skeleton (request," POST" ,true ,body_handler ,
155+ body_generator);
91156 }
92157
93- responsepost (requestconst & request, body_callback_function_type callback,
158+ /* *
159+ * Perform a POST request.
160+ *
161+ * @param[in] request The request including the URI and headers.
162+ * @param[in] body_generator The function to call to generate part of the body
163+ * while the request is being performed.
164+ * @param[in] callback If provided, the function to call for parts of the
165+ * response's body as they come in.
166+ * @returns A response object.
167+ * @throws std::exception May throw exceptions derived from std::exception in
168+ * case of errors.
169+ */
170+ responsepost (requestconst & request, body_callback_function_type body_handler,
94171 body_generator_function_type body_generator =
95172body_generator_function_type ()) {
96- return post (request,string_type (),string_type (),callback ,
97- body_generator);
173+ return post (request,string_type (),string_type (),body_handler ,
174+ body_generator);
98175 }
99176
177+ /* *
178+ * Perform a POST request.
179+ *
180+ * @param[in] request The request object including the URI and headers.
181+ * @param[in] body The whole contents of the body.
182+ * @param[in] body_handler The callback invoked for parts of the response body
183+ * as they come in.
184+ * @param[in] body_generator If provided, is invoked to generate parts of the
185+ * request's body as it is being sent.
186+ * @returns A response object.
187+ * @throws std::exception May throw exceptions on errors, derived from
188+ * `std::exception`.
189+ */
100190 responsepost (requestconst & request, string_typeconst & body,
101- body_callback_function_typecallback ,
191+ body_callback_function_typebody_handler ,
102192 body_generator_function_type body_generator =
103193body_generator_function_type ()) {
104- return post (request, body,string_type (),callback , body_generator);
194+ return post (request, body,string_type (),body_handler , body_generator);
105195 }
106196
197+ /* *
198+ * Perform a PUT request.
199+ *
200+ * @param[in] request A copy of the request object including the URI and
201+ * headers.
202+ * @param[in] body The whole contents of the body. If provided, this overrides
203+ * the body in the `request`.
204+ * @param[in] content_type The content type for the request. This overrides
205+ * the content type in the `request`.
206+ * @param[in] body_handler The callback invoked for parts of the response body
207+ * as they come in.
208+ * @param[in] body_generator If provided, is invoked to generate parts of the
209+ * request's body as it is being sent.
210+ * @returns A response object.
211+ * @throws std::exception May throw exceptions on errors, derived from
212+ * `std::exception`.
213+ */
107214 responseput (request request, string_typeconst & body = string_type(),
108215 string_typeconst & content_type = string_type(),
109216 body_callback_function_type body_handler =
@@ -133,26 +240,62 @@ struct basic_client_facade {
133240 body_generator);
134241 }
135242
243+ /* *
244+ * Perform a PUT request.
245+ *
246+ * @param[in] request The request including the URI and headers.
247+ * @param[in] callback If provided, the function to call for parts of the
248+ * response's body as they come in.
249+ * @param[in] body_generator The function to call to generate part of the body
250+ * while the request is being performed.
251+ * @returns A response object.
252+ * @throws std::exception May throw exceptions derived from std::exception in
253+ * case of errors.
254+ */
136255 responseput (requestconst & request, body_callback_function_type callback,
137256 body_generator_function_type body_generator =
138257body_generator_function_type ()) {
139258return put (request,string_type (),string_type (), callback, body_generator);
140259 }
141260
261+ /* *
262+ * Perform a POST request.
263+ *
264+ * @param[in] request The request object including the URI and headers.
265+ * @param[in] body The whole contents of the body.
266+ * @param[in] body_handler The callback invoked for parts of the response body
267+ * as they come in.
268+ * @param[in] body_generator If provided, is invoked to generate parts of the
269+ * request's body as it is being sent.
270+ * @returns A response object.
271+ * @throws std::exception May throw exceptions on errors, derived from
272+ * `std::exception`.
273+ */
142274 responseput (requestconst & request, string_type body,
143- body_callback_function_type callback,
144- body_generator_function_type body_generator =
145- body_generator_function_type ()) {
146- return put (request, body,string_type (), callback, body_generator);
275+ body_callback_function_type body_handler,
276+ body_generator_function_type body_generator = {}) {
277+ return put (request, body,string_type (), body_handler, body_generator);
147278 }
148279
280+ /* *
281+ * Perform a DELETE request.
282+ *
283+ * @param[in] request The request object including the URI and the headers.
284+ * @param[in] body_handler The callback invoked for parts of the response body
285+ * as they come in, if provided.
286+ * @returns A response object.
287+ * @throws std::exception May throw exceptions on errors, derived from
288+ * `std::exception`.
289+ */
149290 responsedelete_ (requestconst & request,
150- body_callback_function_type body_handler =
151- body_callback_function_type ()) {
291+ body_callback_function_type body_handler = {}) {
152292return pimpl->request_skeleton (request," DELETE" ,true , body_handler,
153293body_generator_function_type ());
154294 }
155295
296+ /* *
297+ * Clears the cache of resolved endpoints.
298+ */
156299void clear_resolved_cache () { pimpl->clear_resolved_cache (); }
157300
158301protected: