22 #include "rest_processor.h"
24 #include <core/exception.h>
25 #include <logging/logger.h>
26 #include <utils/misc/string_split.h>
27 #include <webview/error_reply.h>
28 #include <webview/rest_api.h>
29 #include <webview/rest_api_manager.h>
30 #include <webview/url_manager.h>
53 : url_mgr_(url_manager),
62 for (
const auto &method : methods_) {
65 std::bind(&WebviewRESTRequestProcessor::process_request,
67 std::placeholders::_1));
74 for (
const auto &method : methods_) {
82 std::string rest_url =
"/" + request->
path_arg(
"rest_url");
83 std::vector<std::string> rest_url_parts{str_split(rest_url,
'/')};
85 if (rest_url_parts.empty()) {
86 return new StaticWebReply(WebReply::HTTP_NOT_FOUND,
"REST API overview not yet implemented\n");
89 std::string rest_path = rest_url.substr(rest_url_parts[0].length() + 1);
90 std::string rest_api = rest_url_parts[0];
93 logger_->
log_error(
"WebRESTProc",
"REST API '%s' unknown", rest_api.c_str());
94 return new StaticWebReply(WebReply::HTTP_NOT_FOUND,
"REST API '" + rest_api +
"' unknown\n");
101 "REST API '" + rest_api +
"' has no endpoint '" + rest_path
106 logger_->
log_error(
"WebRESTProc",
"REST API '%s' failed, exception follows", rest_api.c_str());
~WebviewRESTRequestProcessor()
Destructor.
WebviewRESTRequestProcessor(fawkes::WebUrlManager *url_manager, fawkes::WebviewRestApiManager *api_mgr, fawkes::Logger *logger)
Constructor.
Base class for exceptions in Fawkes.
virtual const char * what_no_backtrace() const noexcept
Get primary string (does not implicitly print the back trace).
virtual void log_error(const char *component, const char *format,...)=0
Log error message.
Web request meta data carrier.
std::string path_arg(const std::string &what) const
Get a path argument.
void remove_handler(WebRequest::Method method, const std::string &path)
Remove a request processor.
void add_handler(WebRequest::Method method, const std::string &path, Handler handler)
Add a request processor.
WebviewRestApi * get_api(std::string &name)
Find API by name.
Webview REST API component.
WebReply * process_request(const WebRequest *request, const std::string &rest_url)
Process REST API request.
Fawkes library namespace.
WebReply * no_caching(WebReply *reply)
Disable caching on a reply.