{"id":20163365,"url":"https://github.com/sjinks/jsonrpc-cpp","last_synced_at":"2026-05-15T05:08:53.780Z","repository":{"id":259866965,"uuid":"879674216","full_name":"sjinks/jsonrpc-cpp","owner":"sjinks","description":"JSON-RPC 2.0 server library","archived":false,"fork":false,"pushed_at":"2026-05-01T21:48:37.000Z","size":258,"stargazers_count":1,"open_issues_count":6,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-05-01T23:28:32.421Z","etag":null,"topics":["json-rpc","json-rpc-api","json-rpc-library","json-rpc2","jsonrpc","jsonrpc2"],"latest_commit_sha":null,"homepage":"https://sjinks.github.io/jsonrpc-cpp/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sjinks.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"custom":["https://www.paypal.com/donate/?hosted_button_id=SAG6877JDJ3KU","https://send.monobank.ua/jar/7rosVfiwKM"]}},"created_at":"2024-10-28T10:53:56.000Z","updated_at":"2026-05-01T21:48:39.000Z","dependencies_parsed_at":"2024-10-28T14:22:41.298Z","dependency_job_id":"41f85fdc-49f3-453a-a669-dc0d62207212","html_url":"https://github.com/sjinks/jsonrpc-cpp","commit_stats":null,"previous_names":["sjinks/jsonrpc-cpp"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/sjinks/jsonrpc-cpp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sjinks%2Fjsonrpc-cpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sjinks%2Fjsonrpc-cpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sjinks%2Fjsonrpc-cpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sjinks%2Fjsonrpc-cpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sjinks","download_url":"https://codeload.github.com/sjinks/jsonrpc-cpp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sjinks%2Fjsonrpc-cpp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33054486,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-13T13:14:54.681Z","status":"online","status_checked_at":"2026-05-15T02:00:06.351Z","response_time":103,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["json-rpc","json-rpc-api","json-rpc-library","json-rpc2","jsonrpc","jsonrpc2"],"created_at":"2024-11-14T00:29:14.572Z","updated_at":"2026-05-15T05:08:53.766Z","avatar_url":"https://github.com/sjinks.png","language":"C++","funding_links":["https://www.paypal.com/donate/?hosted_button_id=SAG6877JDJ3KU","https://send.monobank.ua/jar/7rosVfiwKM"],"categories":[],"sub_categories":[],"readme":"# JSON RPC\n\n[![Build and Test](https://github.com/sjinks/jsonrpc-cpp/actions/workflows/ci.yml/badge.svg)](https://github.com/sjinks/jsonrpc-cpp/actions/workflows/ci.yml)\n[![CodeQL](https://github.com/sjinks/jsonrpc-cpp/actions/workflows/codeql.yml/badge.svg)](https://github.com/sjinks/jsonrpc-cpp/actions/workflows/codeql.yml)\n\nJSON-RPC 2.0 library for C++\n\n## Introduction\n\nThis library provides a robust implementation of the JSON-RPC 2.0 protocol for C++. It allows you to easily handle JSON-RPC requests, and manage responses.\n\n## Features\n\n- Full support for JSON-RPC 2.0\n- Easy-to-use API\n- Error handling and validation\n\n## Installation\n\nTo install the library, follow these steps:\n\n1. Clone the repository:\n    ```sh\n    git clone https://github.com/sjinks/jsonrpc-cpp.git\n    cd jsonrpc-cpp\n    ```\n\n2. The library depends on [`nlohmann-json`](https://github.com/nlohmann/json). However, if you do not have it installed, it will be downloaded from the GitHub repository.\n\n3. Build the project using CMake:\n    ```sh\n    cmake -B build -DCMAKE_BUILD_TYPE=Release\n    cmake --build build\n    ```\n\n4. Install the library:\n    ```sh\n    cmake --install build # In Linux, you may have to use `sudo`\n    ```\n\n## Usage\n\n### Basic Usage\n\n```cpp\n#include \u003cwwa/jsonrpc/dispatcher.h\u003e\n\nclass my_server {\npublic:\n    my_server()\n    {\n        this-\u003em_dispatcher.add(\"add\", \u0026my_server::add, this);\n    }\n\n    void handle_request()\n    {\n        // Read the request somehow\n        const std::string input = read_request();\n\n        try {\n            const auto json     = nlohmann::json::parse(input);\n            const auto result   = this-\u003em_dispatcher.process_request(json);\n            const auto response = wwa::json_rpc::serialize_repsonse(result);\n            if (!response.empty()) {\n                // Send the response\n                send_response(response);\n            }\n        }\n        catch (const nlohmann::json::exception\u0026 e) {\n            send_response(\n                wwa::json_rpc::generate_error_response(\n                    {wwa::json_rpc::exception::PARSE_ERROR, e.what()}\n                )\n            );\n        }\n    }\n\nprivate:\n    wwa::json_rpc::dispatcher m_dispatcher;\n\n    int add(int a, int b)\n    {\n        return a + b;\n    }\n};\n```\n\n### Advanced Usage\n\nSometimes, it may be necessary to pass some additional information to the handler. For example, an IP address of the client or authentication information.\n\nMethod handlers can accept a `context` parameter. That parameter is constructed from the data passed `dispatcher::process_request()` method and\nadditional fields from the JSON RPC request.\n\nFor example,\n\n```cpp\nstruct extra_data {\n    std::string ip;\n};\n\nclass my_server {\npublic:\n    my_server()\n    {\n        this-\u003em_dispatcher.add_ex(\"add\", \u0026my_server::add, this);\n    }\n\n    void handle_request()\n    {\n        // Read the request somehow\n        const nlohmann::json input = read_request();\n\n        extra_data extra;\n        extra.ip = get_peer_ip(); // Returns the IP of the client\n\n        const auto response = wwa::json_rpc::serialize_repsonse(this-\u003em_dispatcher.process_request(input, extra));\n        if (!response.empty()) {\n            // Send the response\n            send_response(response);\n        }\n    }\n\nprivate:\n    wwa::json_rpc::dispatcher m_dispatcher;\n\n    int add(const wwa::json_rpc::dispatcher::context_t\u0026 ctx, int a, int b)\n    {\n        std::cout \u003c\u003c \"IP address is \" \u003c\u003c std::any_cast\u003cextra_data\u003e(ctx.first).ip \u003c\u003c \"\\n\";\n        return a + b;\n    }\n};\n```\n\nIt is also possible to get the extra fields form the JSON RPC request.\n\nFor example, given the request:\n\n```json\n{\n    \"jsonrpc\": \"2.0\",\n    \"method\": \"subtract\",\n    \"params\": {\"minuend\": 42, \"subtrahend\": 23},\n    \"id\": 1,\n    \"auth\": \"secret\",\n    \"user\": \"admin\"\n}\n```\n\nThere are extra fields in the request: `auth` and `user`. These fields will be collected into an object and passed as a part of the context.\n\n```cpp\nint my_method(const wwa::json_rpc::dispatcher::context_t\u0026 ctx, int a, int b)\n{\n    const auto\u0026 extra = ctx.second;\n    std::string auth = extra.at(\"auth\");\n    std::string user = extra.at(\"user\");\n    // ...\n}\n```\n\nThere are more examples available in the [test](https://github.com/sjinks/jsonrpc-cpp/tree/master/test) subdirectory\n(you may want to look at `base.h`/`base.cpp` or `test_extra_param.cpp`)\n\nThe documentation is available at https://sjinks.github.io/jsonrpc-cpp/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsjinks%2Fjsonrpc-cpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsjinks%2Fjsonrpc-cpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsjinks%2Fjsonrpc-cpp/lists"}