36
36
#pragma once
37
37
38
38
#include < functional> // for function
39
- #include < map> // for map, map<>::mapped_type
40
- #include < string> // for string, basic_string
39
+ #include < map> // for map
40
+ #include < string> // for string
41
41
#include < utility> // for pair
42
42
43
- #include < cloe/core.hpp> // for Confable, Json
43
+ #include < fable/confable.hpp> // for Confable
44
+ #include < fable/json.hpp> // for Json
44
45
45
46
namespace cloe {
46
47
@@ -148,7 +149,7 @@ class Request {
148
149
/* *
149
150
* Helper method that tries to convert the body to a JSON object.
150
151
*/
151
- virtual Json as_json () const { return fable::parse_json (body ()); }
152
+ virtual fable:: Json as_json () const { return fable::parse_json (body ()); }
152
153
};
153
154
154
155
/* *
@@ -274,7 +275,7 @@ class Response {
274
275
* - When NDEBUG is set, then the serialization of JSON to string does not
275
276
* pretty print.
276
277
*/
277
- void set_body (const Json& js) {
278
+ void set_body (const fable:: Json& js) {
278
279
#ifdef NDEBUG
279
280
this ->set_body (js.dump (), ContentType::JSON);
280
281
#else
@@ -285,28 +286,28 @@ class Response {
285
286
/* *
286
287
* Write is an alias for `set_body(Json)`, for historical reasons.
287
288
*/
288
- void write (const Json& js) { this ->set_body (js); }
289
+ void write (const fable:: Json& js) { this ->set_body (js); }
289
290
290
291
/* *
291
292
* Use bad_request when the method is correct, but the body content is not
292
293
* correct.
293
294
*/
294
- void bad_request (const Json& js) { this ->error (StatusCode::BAD_REQUEST, js); }
295
+ void bad_request (const fable:: Json& js) { this ->error (StatusCode::BAD_REQUEST, js); }
295
296
296
297
/* *
297
298
* Use not_found when the resource in question is not available.
298
299
*/
299
- void not_found (const Json& js) { this ->error (StatusCode::NOT_FOUND, js); }
300
+ void not_found (const fable:: Json& js) { this ->error (StatusCode::NOT_FOUND, js); }
300
301
301
302
/* *
302
303
* Use not_allowed when the method (GET, POST, PUT, DELETE) is not allowed.
303
304
*
304
305
* Specify in `allow` which method is allowed:
305
306
* ```
306
- * r.not_allowed(RequestMethod::POST, Json{{"error", "try something else"}});
307
+ * r.not_allowed(RequestMethod::POST, fable:: Json{{"error", "try something else"}});
307
308
* ```
308
309
*/
309
- void not_allowed (const RequestMethod& allow, const Json& js) {
310
+ void not_allowed (const RequestMethod& allow, const fable:: Json& js) {
310
311
this ->set_status (StatusCode::NOT_ALLOWED);
311
312
this ->set_header (" Allow" , as_cstr (allow));
312
313
this ->set_body (js);
@@ -316,14 +317,14 @@ class Response {
316
317
* Use not_implemented when the functionality represented by the endpoint
317
318
* is not implemented yet.
318
319
*/
319
- void not_implemented (const Json& js) { this ->error (StatusCode::NOT_IMPLEMENTED, js); }
320
+ void not_implemented (const fable:: Json& js) { this ->error (StatusCode::NOT_IMPLEMENTED, js); }
320
321
321
322
/* *
322
323
* Use server_error when an internal error occurred, such as a panic.
323
324
*/
324
- void server_error (const Json& js) { this ->error (StatusCode::SERVER_ERROR, js); }
325
+ void server_error (const fable:: Json& js) { this ->error (StatusCode::SERVER_ERROR, js); }
325
326
326
- void error (StatusCode code, const Json& js) {
327
+ void error (StatusCode code, const fable:: Json& js) {
327
328
this ->set_body (js);
328
329
this ->set_status (code);
329
330
}
@@ -374,11 +375,11 @@ class Redirect {
374
375
*/
375
376
class StaticJson {
376
377
public:
377
- StaticJson (Json j) : data_(j) {} // NOLINT
378
+ StaticJson (fable:: Json j) : data_(j) {} // NOLINT
378
379
void operator ()(const cloe::Request&, cloe::Response& r) { r.write (data_); }
379
380
380
381
private:
381
- const Json data_;
382
+ const fable:: Json data_;
382
383
};
383
384
384
385
/* *
@@ -387,14 +388,14 @@ class StaticJson {
387
388
* - It requires a pointer as input, as it assumes that the data will change.
388
389
* - The type of the pointer must have the associated `to_json` function
389
390
* implemented. In other words, it must be directly convertible to a
390
- * `cloe ::Json`.
391
+ * `fable ::Json`.
391
392
*/
392
393
template <typename T>
393
394
class ToJson {
394
395
public:
395
396
explicit ToJson (const T* ptr) : ptr_(ptr) {}
396
397
void operator ()(const cloe::Request&, cloe::Response& r) {
397
- Json j;
398
+ fable:: Json j;
398
399
to_json (j, *ptr_);
399
400
r.set_body (j);
400
401
}
@@ -417,12 +418,12 @@ class ToJson {
417
418
*/
418
419
class FromConf {
419
420
public:
420
- explicit FromConf (Confable* ptr, bool query_map_as_json = true )
421
+ explicit FromConf (fable:: Confable* ptr, bool query_map_as_json = true )
421
422
: ptr_(ptr), convert_(query_map_as_json) {}
422
423
void operator ()(const cloe::Request& q, cloe::Response& r);
423
424
424
425
private:
425
- Confable* ptr_;
426
+ fable:: Confable* ptr_;
426
427
bool convert_;
427
428
};
428
429
0 commit comments