Represents a JSON-RPC request.
More...
#include <request.hpp>
|
| Request (std::string method, const std::optional< nlohmann::json > ¶ms=std::nullopt, std::optional< nlohmann::json > id=std::nullopt) |
| Constructs a Request object.
|
|
auto | ToJson () const -> nlohmann::json |
| Serializes the Request object to a JSON object.
|
|
auto | GetMethod () const -> std::string |
| Gets the method name.
|
|
auto | GetParams () const -> std::optional< nlohmann::json > |
| Gets the parameters.
|
|
auto | GetId () const -> std::optional< nlohmann::json > |
| Gets the request ID.
|
|
Represents a JSON-RPC request.
Definition at line 13 of file request.hpp.
◆ Request()
jsonrpc::server::Request::Request |
( |
std::string | method, |
|
|
const std::optional< nlohmann::json > & | params = std::nullopt, |
|
|
std::optional< nlohmann::json > | id = std::nullopt ) |
|
explicit |
Constructs a Request object.
- Parameters
-
method | The name of the method to be invoked. |
params | The parameters for the method (optional). |
id | The ID of the request (optional). |
Definition at line 5 of file request.cpp.
8 : method_(std::move(method)), params_(params), id_(std::move(id)) {
9}
◆ FromJson()
auto jsonrpc::server::Request::FromJson |
( |
const nlohmann::json & | json_obj | ) |
-> Request |
|
static |
Creates a Request object from a JSON object.
- Parameters
-
jsonObj | The JSON object representing the request. |
- Returns
- A Request object.
Definition at line 11 of file request.cpp.
11 {
12 auto params = json_obj.contains("params")
13 ? std::optional<nlohmann::json>(json_obj["params"])
14 : std::nullopt;
15
16 auto id = json_obj.contains("id")
17 ? std::optional<nlohmann::json>(json_obj["id"])
18 : std::nullopt;
19 return Request(json_obj[
"method"], params,
id);
20}
Request(std::string method, const std::optional< nlohmann::json > ¶ms=std::nullopt, std::optional< nlohmann::json > id=std::nullopt)
Constructs a Request object.
◆ GetId()
auto jsonrpc::server::Request::GetId |
( |
| ) |
const -> std::optional<nlohmann::json> |
|
inlinenodiscard |
◆ GetMethod()
auto jsonrpc::server::Request::GetMethod |
( |
| ) |
const -> std::string |
|
inlinenodiscard |
Gets the method name.
Definition at line 43 of file request.hpp.
43 {
44 return method_;
45 }
◆ GetParams()
auto jsonrpc::server::Request::GetParams |
( |
| ) |
const -> std::optional<nlohmann::json> |
|
inlinenodiscard |
Gets the parameters.
Definition at line 48 of file request.hpp.
48 {
49 return params_;
50 }
◆ ToJson()
auto jsonrpc::server::Request::ToJson |
( |
| ) |
const -> nlohmann::json |
|
nodiscard |
Serializes the Request object to a JSON object.
- Returns
- The JSON representation of the request.
Definition at line 22 of file request.cpp.
22 {
23 nlohmann::json json_obj;
24 json_obj["jsonrpc"] = "2.0";
25 json_obj["method"] = method_;
26 if (params_.has_value()) {
27 json_obj["params"] = params_.value();
28 }
29 if (id_.has_value()) {
30 json_obj["id"] = id_.value();
31 }
32 return json_obj;
33}
The documentation for this class was generated from the following files: