Skip to content

a-kuntz/JsonRPC

Repository files navigation

JsonRPC

Modern C++ JSON RPC 2.0 library

Use the library

Server

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

Client

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

More examples

You can find additional usage examples in the test folder, in particular see client server test.

Building the library

Install development tools

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

Clone the repo

git clone https://github.com/a-kuntz/JsonRPC.git
cd JsonRPC

Build

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

Dependencies

JsonRPC directly depends on the following libraries, which are handled through conan (see conanfile.txt for details):

tool requirement
g++/clang c++17
cmake version 3.16
conan version 1.53

About

Modern C++ JSON RPC library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published