Modern C++ JSON RPC 2.0 library
struct Foo : public rpc::IMethod
{
rpc::Json call(const rpc::Json& data) override
{
// your custom foo implementation
return "foo called";
}
};
int main(int argc, char* argv[])
{
boost::asio::io_context io_context;
rpc::Dispatcher dispatcher;
dispatcher.add<Foo>("foo");
net::ServerTransport st(io_context, 5555, dispatcher);
io_context.run();
}
See server example
int main(int argc, char* argv[])
{
boost::asio::io_context io_context;
net::ClientTransport transport(io_context);
transport.connect("localhost", 5555);
auto client = rpc::Client(transport);
client.call("foo", {"arg1", "arg2", "arg3"});
}
See client example
You can find additional usage examples in the test folder, in particular see client server test.
On an Ubuntu 20.04, to setup your machine for building the library, execute the following command:
wget -qO - https://raw.githubusercontent.com/a-kuntz/JsonRPC/master/scripts/bootstrap-ubuntu-20-04.sh | sh
git clone https://github.com/a-kuntz/JsonRPC.git
cd JsonRPC
To build the library, use the convenience build script
./build.sh Debug
or build manually
conan install . --install-folder=build -pr:b=default -s build_type=Debug --build=missing
cmake -B build -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Debug
cmake --build build
cmake --build build --target test
JsonRPC directly depends on the following libraries, which are handled through conan (see conanfile.txt for details):
- boost version 1.75.0
- fmt version 7.1.3
- gtest version 1.11.0 (for testing purposes only)
- nlohmann_json vesion 3.9.1
tool | requirement |
---|---|
g++/clang | c++17 |
cmake | version 3.16 |
conan | version 1.53 |