Convenient base for handlers that accept requests with body in JSON format and respond with body in JSON format.
Example usage:
struct ConfigDataWithTimestamp {
std::chrono::system_clock::time_point updated_at;
std::unordered_map<std::string, formats::json::Value> key_values;
};
public:
static constexpr std::string_view kName = "handler-config";
using KeyValues = std::unordered_map<std::string, formats::json::Value>;
void SetNewValues(KeyValues&& key_values) {
config_values_.Assign(ConfigDataWithTimestamp{
std::move(key_values),
});
}
private:
};
- Examples
- samples/config_service/config_service.cpp, samples/testsuite-support/src/metrics.cpp, and samples/testsuite-support/src/metrics.hpp.
Definition at line 25 of file http_handler_json_base.hpp.
|
| HttpHandlerJsonBase (const components::ComponentConfig &config, const components::ComponentContext &component_context, bool is_monitor=false) |
|
std::string | HandleRequestThrow (const http::HttpRequest &request, request::RequestContext &context) const final |
|
virtual formats::json::Value | HandleRequestJsonThrow (const http::HttpRequest &request, const formats::json::Value &request_json, request::RequestContext &context) const =0 |
|
Public Member Functions inherited from server::handlers::HttpHandlerBase |
| HttpHandlerBase (const components::ComponentConfig &config, const components::ComponentContext &component_context, bool is_monitor=false) |
|
void | HandleRequest (request::RequestBase &request, request::RequestContext &context) const override |
|
void | ReportMalformedRequest (request::RequestBase &request) const final |
|
virtual const std::string & | HandlerName () const |
|
const std::vector< http::HttpMethod > & | GetAllowedMethods () const |
|
virtual logging::Level | GetLogLevelForResponseStatus (http::HttpStatus status) const |
|
std::string | GetResponseDataForLoggingChecked (const http::HttpRequest &request, request::RequestContext &context, const std::string &response_data) const |
|
void | HandleCustomHandlerException (const http::HttpRequest &request, const CustomHandlerException &ex) const |
|
void | HandleUnknownException (const http::HttpRequest &request, const std::exception &ex) const |
|
void | LogUnknownException (const std::exception &ex) const |
| Helper function to log an unknown exception.
|
|
const std::optional< logging::Level > & | GetLogLevel () const |
| Returns the default log level for the handler.
|
|
Public Member Functions inherited from server::handlers::HandlerBase |
| HandlerBase (const components::ComponentConfig &config, const components::ComponentContext &component_context, bool is_monitor=false) |
|
bool | IsMonitor () const |
| Returns whether this is a monitoring handler.
|
|
const HandlerConfig & | GetConfig () const |
| Returns handler config.
|
|
| LoggableComponentBase (const ComponentConfig &, const ComponentContext &) |
|
| LoggableComponentBase (LoggableComponentBase &&)=delete |
|
| LoggableComponentBase (const LoggableComponentBase &)=delete |
|
| ~LoggableComponentBase () override=default |
|
ComponentHealth | GetComponentHealth () const override |
|
void | OnLoadingCancelled () override |
|
void | OnAllComponentsLoaded () override |
|
void | OnAllComponentsAreStopping () override |
|