2
3
4
18 this->d_ptr->add_handler(std::string(method), std::move(handler));
25 req = nlohmann::json::parse(request);
27 catch (
const nlohmann::json::exception& e) {
28 this->on_request(extra);
29 const auto json = dispatcher_private::generate_error_response(
30 exception(exception::PARSE_ERROR, e.what()), nlohmann::json(
nullptr)
33 this->on_request_processed({}, exception::PARSE_ERROR, extra);
37 return this->process_request(req, extra);
42 const auto json =
this->d_ptr->process_request(request, extra);
43 return json.is_discarded() ? std::string{} : json.dump();
A class that manages JSON RPC method handlers and processes JSON RPC requests.
virtual void on_request(const nlohmann::json &extra)
Invoked when a request is received.
std::string parse_and_process_request(const std::string &request, const nlohmann::json &extra=nlohmann::json::object())
Parses and processes a JSON RPC request.
std::string process_request(const nlohmann::json &request, const nlohmann::json &extra=nlohmann::json::object())
Processes a JSON RPC request.
virtual void on_request_processed(const std::string &method, int code, const nlohmann::json &extra)
Invoked after the method handler is called.
void add_internal_method(std::string_view method, handler_t &&handler)
Adds a method handler for the specified method.
virtual void on_method(const std::string &method, const nlohmann::json &extra)
Invoked right before the method handler is called.
dispatcher()
Class constructor.
virtual ~dispatcher()
Class destructor.