26#ifndef MYSQLROUTER_REST_API_UTILS_INCLUDED
27#define MYSQLROUTER_REST_API_UTILS_INCLUDED
33#ifdef RAPIDJSON_NO_SIZETYPEDEFINE
37#include <rapidjson/document.h>
57 const std::map<std::string, std::string> &fields);
124 const rapidjson::Document &json_doc);
129template <
class Encoding,
class AllocatorType>
131 std::chrono::time_point<std::chrono::system_clock> tp,
132 AllocatorType &allocator) {
133 time_t cur = std::chrono::system_clock::to_time_t(tp);
134 struct tm cur_gmtime;
136 gmtime_s(&cur_gmtime, &cur);
138 gmtime_r(&cur, &cur_gmtime);
140 auto usec = std::chrono::duration_cast<std::chrono::microseconds>(
141 tp - std::chrono::system_clock::from_time_t(cur));
144 "%04d-%02d-%02dT%02d:%02d:%02d.%06ldZ", cur_gmtime.tm_year + 1900,
145 cur_gmtime.tm_mon + 1, cur_gmtime.tm_mday, cur_gmtime.tm_hour,
146 cur_gmtime.tm_min, cur_gmtime.tm_sec,
149 static_cast<long int>(usec.count()))};
151 return {iso8601_datetime.c_str(), iso8601_datetime.size(), allocator};
a HTTP request and response.
Definition: http_request.h:453
Define rapidjson::SizeType to be std::size_t.
std::bitset< Pos::_LAST+1 > Bitset
Definition: http_request.h:268
int key_type
Definition: http_request.h:50
HARNESS_EXPORT std::string string_format(const char *format,...)
Definition: utilities.cc:64
void send_json_document(HttpRequest &req, HttpStatusCode::key_type status_code, const rapidjson::Document &json_doc)
send json document as HTTP response.
Definition: rest_api_utils.cc:39
bool ensure_modified_since(HttpRequest &req, time_t last_modified)
ensure resource has modified since client received it.
Definition: rest_api_utils.cc:159
bool ensure_auth(HttpRequest &req, const std::string require_realm)
ensure request is authenticated.
Definition: rest_api_utils.cc:130
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:130
void send_rfc7807_not_found_error(HttpRequest &req)
send a JsonProblem "Not Found" error.
Definition: rest_api_utils.cc:83
bool ensure_no_params(HttpRequest &req)
ensure request has no parameters.
Definition: rest_api_utils.cc:146
bool ensure_http_method(HttpRequest &req, HttpMethod::Bitset allowed_methods)
ensure HTTP method is allowed.
Definition: rest_api_utils.cc:91
void send_rfc7807_error(HttpRequest &req, HttpStatusCode::key_type status_code, const std::map< std::string, std::string > &fields)
send a JsonProblem HTTP response.
Definition: rest_api_utils.cc:61