{"id":15077655,"url":"https://github.com/mops1k/json-rpc-bundle","last_synced_at":"2026-01-29T03:34:14.198Z","repository":{"id":245512920,"uuid":"817939873","full_name":"mops1k/json-rpc-bundle","owner":"mops1k","description":"This bundle provides easy way to up your json-rpc server on symfony with parameters validation and possibility to get parameters as DTO object inside method.","archived":false,"fork":false,"pushed_at":"2024-07-27T08:57:24.000Z","size":113,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-31T16:55:24.253Z","etag":null,"topics":["api-documentation","json-rpc-server","library","symfony-bundle"],"latest_commit_sha":null,"homepage":"","language":"PHP","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/mops1k.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":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-20T19:01:54.000Z","updated_at":"2024-07-30T09:08:02.000Z","dependencies_parsed_at":"2024-07-27T09:55:44.871Z","dependency_job_id":null,"html_url":"https://github.com/mops1k/json-rpc-bundle","commit_stats":{"total_commits":31,"total_committers":1,"mean_commits":31.0,"dds":0.0,"last_synced_commit":"48a5e59a8c3b1f02344bef869b0578f4258bdd34"},"previous_names":["mops1k/json-rpc-bundle"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mops1k%2Fjson-rpc-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mops1k%2Fjson-rpc-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mops1k%2Fjson-rpc-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mops1k%2Fjson-rpc-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mops1k","download_url":"https://codeload.github.com/mops1k/json-rpc-bundle/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245679347,"owners_count":20654813,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["api-documentation","json-rpc-server","library","symfony-bundle"],"created_at":"2024-09-25T04:05:33.592Z","updated_at":"2026-01-29T03:34:09.175Z","avatar_url":"https://github.com/mops1k.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JSON-RPC Server bundle\n\nThis bundle provide an easy way to implement json-rpc server with fully specification supporting.\nBundle supports multiple procedure calls in one request as described in specification.\n\n[JSON-RPC](https://www.jsonrpc.org/specification) specification is fully compatible\nwith [CQRS](https://en.wikipedia.org/wiki/Command_Query_Responsibility_Segregation) architecture\n\n## Install\n\n```bash\ncomposer require mops1k/json-rpc-bundle\n```\n\nImport route declaration in your routes:\n\n```yaml\n#config/routes/json-rpc.yaml\napp_file:\n    # loads routes from the given routing file stored in some bundle\n    resource: '@JsonRpcBundle/Resources/config/routing/json-rpc-bundle.yaml'\n```\n\nOr add your own paths by template:\n\n```yaml\njson_rpc_entrypoint:\n    path: '/path/to/rpc'\n    methods: 'POST'\n    controller: 'JsonRpcBundle\\Controller\\JsonRpcController'\n\njson_rpc_namespace_entrypoint:\n    path: '/path/to/rpc/{namespace}'\n    methods: 'POST'\n    controller: 'JsonRpcBundle\\Controller\\JsonRpcController'\n```\n\n## Usage\n\nTo create method you have to create invokable class with\nattribute [`\\JsonRpcBundle\\Attribute\\AsRpcMethod`](./src/Attribute/AsRpcMethod.php), where `methodName` constructor\nparameter must contain method name. Example:\n\n```php\n\u003c?php\n\nuse JsonRpcBundle\\Attribute\\AsRpcMethod;\nuse Symfony\\Component\\Validator\\Constraints\\Collection;\nuse Symfony\\Component\\Validator\\Constraints\\GreaterThanOrEqual;\n\n#[AsRpcMethod('methodWithoutContract')]\nclass MethodWithoutContract\n{\n    public function __invoke(int $id): int\n    {\n        return $id;\n    }\n}\n```\n\n#### Contract request DTO\n\nBundle provide possibility to provide params to your DTO class. For these feature you have to add\nattribute [`\\JsonRpcBundle\\Attribute\\RpcMethodContract`](./src/Attribute/RpcMethodContract.php).\nDTO passed supports validation through [symfony/validator](https://symfony.com/doc/current/validation.html).\nExample:\n\n```php\n\u003c?php\n\nuse JsonRpcBundle\\Attribute\\AsRpcMethod;\nuse JsonRpcBundle\\Attribute\\RpcMethodContract;\nuse JsonRpcBundle\\Tests\\Stubs\\Contract\\Contract;\nuse Symfony\\Component\\Validator\\Constraints as Assert;\n\nreadonly class Contract\n{\n    public function __construct(\n        #[Assert\\GreaterThanOrEqual(0)]\n        public int $id,\n        #[Assert\\NotBlank(allowNull: false)]\n        public ?string $text = null,\n    ) {\n    }\n}\n\n#[AsRpcMethod('methodWithContract')]\n#[RpcMethodContract(Contract::class)]\nclass MethodWithContract\n{\n    public function __invoke(Contract $contract): array\n    {\n        return [\n            'id' =\u003e $contract-\u003eid,\n            'text' =\u003e $contract-\u003etext,\n        ];\n    }\n}\n```\n\n#### Validation for method params without contract\n\nIf you don't want to use DTO, you still able to validate method parameters and set its groups. In this case you need to\nimplement your method class\nfrom [`\\JsonRpcBundle\\MethodResolver\\ValidateMethodParametersInterface`](./src/MethodResolver/ValidateMethodParametersInterface.php).\nExample:\n\n```php\n\u003c?php\n\nuse JsonRpcBundle\\Attribute\\AsRpcMethod;\nuse JsonRpcBundle\\MethodResolver\\ValidateMethodParametersInterface;\nuse Symfony\\Component\\Validator\\Constraints\\Collection;\nuse Symfony\\Component\\Validator\\Constraints\\GreaterThanOrEqual;\nuse Symfony\\Component\\Validator\\Constraints\\GroupSequence;\n\n#[AsRpcMethod('methodWithoutContract')]\nclass MethodWithoutContract implements ValidateMethodParametersInterface\n{\n    public function __invoke(int $id): int\n    {\n        return $id;\n    }\n\n    public function configureValidation(): Collection\n    {\n        return new Collection([\n            'id' =\u003e [\n                new GreaterThanOrEqual(0),\n            ],\n        ], groups: ['rpc']);\n    }\n\n    public function validationGroups(): array|string|GroupSequence|null\n    {\n        return ['rpc'];\n    }\n}\n```\n\n#### Notification\n\nJson rpc supports notification requests what does not return any response. To make your method as notification, just\nadd `void` in `__invoke` return type hint.\nExample:\n\n```php\nuse JsonRpcBundle\\Attribute\\AsRpcMethod;\n\n#[AsRpcMethod('updateUser')]\nclass UpdateUser\n{\n    public function __invoke(int $id): void\n    {\n        // some logic\n    }\n}\n```\n\n#### Namespace\n\nBundle supports method namespacing. To set method namespace, use `\\JsonRpcBundle\\Attribute\\AsRpcMethod::$namespace`\nattribute parameter.\nExample:\n\n```php\nuse JsonRpcBundle\\Attribute\\AsRpcMethod;\n\n#[AsRpcMethod(methodName: 'update', namespace: 'user')]\nclass UpdateUser\n{\n    public function __invoke(int $id): void\n    {\n        // some logic\n    }\n}\n```\n\nTo fetch namespaced method you can call it by method name (`namespace.methodName`) or call to path `/rpc/{namespace}`\nand use regular method name.\nExamples:\n\n1. Call to `/rpc`:\n    ```json\n    {\n      \"jsonrpc\": \"2.0\",\n      \"method\": \"user.update\",\n      \"params\": null,\n      \"id\": 32\n    }\n    ```\n2. Call to `/rpc/user`:\n    ```json\n    {\n      \"jsonrpc\": \"2.0\",\n      \"method\": \"update\",\n      \"params\": null,\n      \"id\": 32\n    }\n    ```\n\n\u003e This feature also supports bath requests.\n\n## API Documentation\n\n![documentation example](./doc-example.png \"documentation example\")\n\nBundle supports documentation semi-auto generation\nthru [nelmio/api-doc-bundle](https://github.com/nelmio/NelmioApiDocBundle).\nBy default documentation generate params from method parameters, method contract. If you need more specific params\ndocumentation,\njust use `OA\\Property` attribute. If you need specific response result, then\nuse `\\JsonRpcBundle\\ApiDoc\\Attribute\\Result`\nattribute (set array of `OA\\Property` inside `$properties` parameter).\nObject responses auto-generated to documentation by it's describing inside class.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmops1k%2Fjson-rpc-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmops1k%2Fjson-rpc-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmops1k%2Fjson-rpc-bundle/lists"}