@@ -24,14 +24,37 @@ template <class Tag>
24
24
struct basic_response ;
25
25
26
26
template <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
+ */
29
34
typedef typename string<Tag>::type string_type;
35
+
36
+ /* * The request type. This models the HTTP Request concept.*/
30
37
typedef basic_request<Tag> request;
38
+
39
+ /* * The response type. This models the HTTP Response concept.*/
31
40
typedef 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
+ */
33
47
typedef function<void (iterator_range<char const *>const &,
34
48
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
+ */
35
58
typedef function<bool (string_type&)> body_generator_function_type;
36
59
37
60
explicit basic_client_facade (client_options<Tag>const & options) {
@@ -40,19 +63,49 @@ struct basic_client_facade {
40
63
41
64
~basic_client_facade () { pimpl->wait_complete (); }
42
65
66
+ /* *
67
+ * Perform a HEAD request.
68
+ */
43
69
responsehead (requestconst & request) {
44
70
return pimpl->request_skeleton (request," HEAD" ,false ,
45
71
body_callback_function_type (),
46
72
body_generator_function_type ());
47
73
}
48
74
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
+ */
49
85
responseget (requestconst & request,
50
86
body_callback_function_type body_handler =
51
87
body_callback_function_type ()) {
52
88
return pimpl->request_skeleton (request," GET" ,true , body_handler,
53
89
body_generator_function_type ());
54
90
}
55
91
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
+ */
56
109
responsepost (request request, string_typeconst & body = string_type(),
57
110
string_typeconst & content_type = string_type(),
58
111
body_callback_function_type body_handler =
@@ -82,28 +135,82 @@ struct basic_client_facade {
82
135
body_generator);
83
136
}
84
137
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
+ */
85
150
responsepost (requestconst & request,
86
151
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);
91
156
}
92
157
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,
94
171
body_generator_function_type body_generator =
95
172
body_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);
98
175
}
99
176
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
+ */
100
190
responsepost (requestconst & request, string_typeconst & body,
101
- body_callback_function_typecallback ,
191
+ body_callback_function_typebody_handler ,
102
192
body_generator_function_type body_generator =
103
193
body_generator_function_type ()) {
104
- return post (request, body,string_type (),callback , body_generator);
194
+ return post (request, body,string_type (),body_handler , body_generator);
105
195
}
106
196
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
+ */
107
214
responseput (request request, string_typeconst & body = string_type(),
108
215
string_typeconst & content_type = string_type(),
109
216
body_callback_function_type body_handler =
@@ -133,26 +240,62 @@ struct basic_client_facade {
133
240
body_generator);
134
241
}
135
242
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
+ */
136
255
responseput (requestconst & request, body_callback_function_type callback,
137
256
body_generator_function_type body_generator =
138
257
body_generator_function_type ()) {
139
258
return put (request,string_type (),string_type (), callback, body_generator);
140
259
}
141
260
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
+ */
142
274
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);
147
278
}
148
279
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
+ */
149
290
responsedelete_ (requestconst & request,
150
- body_callback_function_type body_handler =
151
- body_callback_function_type ()) {
291
+ body_callback_function_type body_handler = {}) {
152
292
return pimpl->request_skeleton (request," DELETE" ,true , body_handler,
153
293
body_generator_function_type ());
154
294
}
155
295
296
+ /* *
297
+ * Clears the cache of resolved endpoints.
298
+ */
156
299
void clear_resolved_cache () { pimpl->clear_resolved_cache (); }
157
300
158
301
protected: