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),
56 methods_{WebRequest::METHOD_GET,
57 WebRequest::METHOD_POST,
58 WebRequest::METHOD_PUT,
59 WebRequest::METHOD_DELETE,
60 WebRequest::METHOD_PATCH}
62 for (
const auto &method : methods_) {
63 url_mgr_->add_handler(method,
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());