Represents a JSON RPC request.
More...
#include <request.h>
|
| nlohmann::json | extra |
| | Extra fields from the JSON RPC request.
|
| nlohmann::json | id |
| | The ID of the request.
|
| std::string | jsonrpc |
| | The JSON RPC version.
|
| std::string | method |
| | The name of the method to be invoked.
|
| nlohmann::json | params |
| | The parameters for the method.
|
Represents a JSON RPC request.
This struct holds the components of a JSON RPC request, including the JSON RPC version, method name, parameters, and ID.
- See also
- https://www.jsonrpc.org/specification#request_object
Definition at line 22 of file request.h.
◆ from_json()
| jsonrpc_request wwa::json_rpc::jsonrpc_request::from_json |
( |
const nlohmann::json & | request | ) |
|
|
static |
Parses and validates a JSON RPC request.
- Parameters
-
| request | The JSON RPC request as a nlohmann::json object. |
- Returns
- The parsed JSON RPC request.
This method extracts the components of a JSON RPC request from the provided JSON object and validates the request, ensuring that all required fields are present and correctly formatted.
- Exceptions
-
- See also
- exception::INVALID_REQUEST, exception::INVALID_PARAMS
Definition at line 62 of file request.cpp.
63{
64 jsonrpc_request req;
65 try {
66 request.get_to(req);
67 }
68 catch (const nlohmann::json::exception&) {
70 }
71
72 if (req.jsonrpc != "2.0") {
74 }
75
76 if (!req.params.is_array()) {
78 }
79
80 if (req.method.empty()) {
82 }
83
86 }
87
88 req.extra = request;
89 req.extra.erase("jsonrpc");
90 req.extra.erase("method");
91 req.extra.erase("params");
92 req.extra.erase("id");
93 return req;
94}
exception(int code, std::string_view message, const T &data)
Construct a new exception object with additional data.
static constexpr int INVALID_PARAMS
Invalid method parameter(s).
static constexpr int INVALID_REQUEST
The JSON sent is not a valid Request object.
WWA_JSONRPC_EXPORT bool is_valid_request_id(const nlohmann::json &id)
Checks if the provided JSON value is a valid JSON RPC request ID.
◆ extra
| nlohmann::json wwa::json_rpc::jsonrpc_request::extra |
Extra fields from the JSON RPC request.
Definition at line 27 of file request.h.
◆ id
| nlohmann::json wwa::json_rpc::jsonrpc_request::id |
The ID of the request.
Definition at line 26 of file request.h.
◆ jsonrpc
| std::string wwa::json_rpc::jsonrpc_request::jsonrpc |
The JSON RPC version.
Definition at line 23 of file request.h.
◆ method
| std::string wwa::json_rpc::jsonrpc_request::method |
The name of the method to be invoked.
Definition at line 24 of file request.h.
◆ params
| nlohmann::json wwa::json_rpc::jsonrpc_request::params |
The parameters for the method.
Definition at line 25 of file request.h.
The documentation for this struct was generated from the following files: