26#ifndef MYSQLROUTER_REST_API_UTILS_INCLUDED
27#define MYSQLROUTER_REST_API_UTILS_INCLUDED
33#ifdef RAPIDJSON_NO_SIZETYPEDEFINE
37#include <rapidjson/document.h>
58 const std::map<std::string, std::string> &fields);
127 const rapidjson::Document &json_doc);
132template <
class Encoding,
class AllocatorType>
134 std::chrono::time_point<std::chrono::system_clock> tp,
135 AllocatorType &allocator) {
136 time_t cur = std::chrono::system_clock::to_time_t(tp);
137 struct tm cur_gmtime;
139 gmtime_s(&cur_gmtime, &cur);
141 gmtime_r(&cur, &cur_gmtime);
143 auto usec = std::chrono::duration_cast<std::chrono::microseconds>(
144 tp - std::chrono::system_clock::from_time_t(cur));
147 "%04d-%02d-%02dT%02d:%02d:%02d.%06ldZ", cur_gmtime.tm_year + 1900,
148 cur_gmtime.tm_mon + 1, cur_gmtime.tm_mday, cur_gmtime.tm_hour,
149 cur_gmtime.tm_min, cur_gmtime.tm_sec,
152 static_cast<long int>(usec.count()))};
154 return {iso8601_datetime.c_str(), iso8601_datetime.size(), allocator};
Define rapidjson::SizeType to be std::uint64_t.
std::bitset< Pos::_LAST+1 > Bitset
Definition: method.h:57
int key_type
Definition: status_code.h:36
HARNESS_EXPORT std::string string_format(const char *format,...)
Definition: utilities.cc:64
bool ensure_no_params(http::base::Request &req)
ensure request has no parameters.
Definition: rest_api_utils.cc:145
bool ensure_auth(http::base::Request &req, const std::string require_realm)
ensure request is authenticated.
Definition: rest_api_utils.cc:129
rapidjson::GenericValue< Encoding, AllocatorType > json_value_from_timepoint(std::chrono::time_point< std::chrono::system_clock > tp, AllocatorType &allocator)
format a timepoint as json-value (date-time format).
Definition: rest_api_utils.h:133
void send_rfc7807_not_found_error(http::base::Request &req)
send a JsonProblem "Not Found" error.
Definition: rest_api_utils.cc:81
bool ensure_modified_since(http::base::Request &req, time_t last_modified)
ensure resource has modified since client received it.
Definition: rest_api_utils.cc:158
void send_json_document(http::base::Request &req, HttpStatusCode::key_type status_code, const rapidjson::Document &json_doc)
send json document as HTTP response.
Definition: rest_api_utils.cc:40
void send_rfc7807_error(http::base::Request &req, HttpStatusCode::key_type status_code, const std::map< std::string, std::string > &fields)
send a JsonProblem HTTP response.
Definition: rest_api_utils.cc:58
bool ensure_http_method(http::base::Request &req, HttpMethod::Bitset allowed_methods)
ensure HTTP method is allowed.
Definition: rest_api_utils.cc:89