JSON-RPC 2.0
JSON-RPC 2.0 Modern C++ Library
Loading...
Searching...
No Matches
request.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <functional>
4#include <optional>
5#include <string>
6
7#include <nlohmann/json.hpp>
8
9namespace jsonrpc::client {
10
17class Request {
18 public:
28 Request(
29 std::string method, std::optional<nlohmann::json> params,
30 bool is_notification, const std::function<int()> &id_generator);
31
33 [[nodiscard]] auto RequiresResponse() const -> bool;
34
36 [[nodiscard]] auto GetKey() const -> int;
37
39 [[nodiscard]] auto Dump() const -> std::string;
40
41 private:
42 std::string method_;
43 std::optional<nlohmann::json> params_;
44 bool is_notification_;
45 int id_;
46};
47
48} // namespace jsonrpc::client
Represents a JSON-RPC request.
Definition request.hpp:17
auto Dump() const -> std::string
Serializes the request to a JSON string.
Definition request.cpp:25
auto GetKey() const -> int
Returns the unique key (ID) for the request.
Definition request.cpp:21
auto RequiresResponse() const -> bool
Checks if the request requires a response.
Definition request.cpp:17
Request(std::string method, std::optional< nlohmann::json > params, bool is_notification, const std::function< int()> &id_generator)
Constructs a new Request object.
Definition request.cpp:5