{"id":15282339,"url":"https://github.com/georgique/yii2-jsonrpc","last_synced_at":"2025-04-12T22:55:06.222Z","repository":{"id":52690839,"uuid":"115389189","full_name":"georgique/yii2-jsonrpc","owner":"georgique","description":"Yii2 JSON-RPC server implementation based on method-to-action translation.","archived":false,"fork":false,"pushed_at":"2024-07-11T09:31:00.000Z","size":107,"stargazers_count":9,"open_issues_count":2,"forks_count":8,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-26T17:01:52.002Z","etag":null,"topics":["json-rpc","json-rpc-api","json-rpc-server","json-rpc2","yii2","yii2-extension"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/georgique.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}},"created_at":"2017-12-26T05:40:03.000Z","updated_at":"2023-11-22T20:12:44.000Z","dependencies_parsed_at":"2022-08-22T06:20:58.508Z","dependency_job_id":null,"html_url":"https://github.com/georgique/yii2-jsonrpc","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/georgique%2Fyii2-jsonrpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/georgique%2Fyii2-jsonrpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/georgique%2Fyii2-jsonrpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/georgique%2Fyii2-jsonrpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/georgique","download_url":"https://codeload.github.com/georgique/yii2-jsonrpc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248571841,"owners_count":21126522,"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":["json-rpc","json-rpc-api","json-rpc-server","json-rpc2","yii2","yii2-extension"],"created_at":"2024-09-30T14:25:13.258Z","updated_at":"2025-04-12T22:55:06.204Z","avatar_url":"https://github.com/georgique.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Yii2 JSON-RPC\n\nYii2 extension for JSON-RPC server implementation. Works not as Remote Procedure Call, but Remote Action Call, therefor leaves all Yii2 power for your service.\n\n[![Build Status](https://travis-ci.org/georgique/yii2-jsonrpc.svg?branch=master)](https://travis-ci.org/georgique/yii2-jsonrpc)\n\n## Features\n* Uses full Yii2 power, because method string is translated into a route. \n* Lightweight.\n* Fully [JSON-RPC 2.0](http://www.jsonrpc.org/specification) compliant.\n\n\n## Usage\nEntry point:\n```php\n\u003c?php\n\nnamespace app\\controllers;\nuse \\georgique\\yii2\\jsonrpc\\Controller;\n\nclass JsonRpcController extends Controller {\n\n\t// Practically you don't need anything else in this controller, \n\t// unless you want to customize entry point somehow.\n\t\n}\n```\n\nEntry point with different way to pass params:\n```php\n\u003c?php\n\nnamespace app\\controllers;\nuse \\georgique\\yii2\\jsonrpc\\Controller;\n\nclass JsonRpcBodyController extends Controller {\n\n\t// With the customization JSON RPC params will be passed to the target action\n\t// as request body params, not as action function arguments\n    public $paramsPassMethod = self::JSON_RPC_PARAMS_PASS_BODY;\n\n}\n```\n\nController with target actions which we are going to call:\n```php\n\u003c?php\nnamespace app\\modules\\api1\\controllers;\n\n// There are some minor side-effects of this solutions, because original request is made to the\n// entry point, not to the target controller and action. Be careful working with Request object,\n// especially when working on access restriction to the target actions. For example, you want an\n// action to be reached only with GET verb only, but you do POST request to the endpoint. In that\n// case you will get Internal Error because access will be denied.\nclass ExampleController extends \\yii\\web\\Controller {\n\n    // Note that URL patterns won't be used to resolve the method - this would not be resourse-wise.\n    // Method string should simply be [[module.]controller.]action where module and controller parts\n    // can be omitted, so default module and index controller will be used.\n    public function actionTry() {\n        return \"You've got it!\";\n    }\n\n    // Method params are directly translated into action arguments. Make sure your call matches action\n    // signature.\n    public function actionTryWithParams($foo) {\n        return \"Params received: \\$foo = $foo.\";\n    }\n    \n    // Passing params as Yii request body params must be handy too, when we need to do a massive\n    // attribute assignment for example.\n    public function actionTryWithBodyParams() {\n        $output = \"Params received: \";\n        $output_chunks = array();\n        foreach (\\Yii::$app-\u003erequest-\u003egetBodyParams() as $name =\u003e $value) {\n            $output_chunks[] = \"$name = $value\\n\";\n        }\n        return $output . implode(', ', $output_chunks) . '.';\n    }\n \n}\n```\n\nNow this is how calls and responses will look like:\n```\n-\u003e {\"jsonrpc\": \"2.0\", \"method\": \"api1.example.try\", \"id\": 1}\n\u003c- {\"jsonrpc\": \"2.0\", \"result\": \"You've got it!\", \"id\": 1}\n\n-\u003e {\"jsonrpc\": \"2.0\", \"method\": \"api1.example.try-with-params\", \"params\": {\"foo\": \"bar\"}, \"id\": 2}\n\u003c- {\"jsonrpc\": \"2.0\", \"result\": \"Params received: $foo = bar.\", \"id\": 2}\n\n// Using alternative entry point:\n-\u003e {\"jsonrpc\": \"2.0\", \"method\": \"api1.example.try-with-body-params\", \"params\": {\"foo\": \"bar\", \"foo1\": \"bar1\"}, \"id\": 2}\n\u003c- {\"jsonrpc\": \"2.0\", \"result\": \"Params received: $foo = bar, $foo1 = bar1.\", \"id\": 2}\n\n-\u003e {\"jsonrpc\": \"2.0\", \"method\": \"api1.example.garbage\", \"id\": 3}\n\u003c- {\"jsonrpc\": \"2.0\", \"error\": {\"code\": -32601, \"message\": \"Method not found.\"}, \"id\": 3}\n\n-\u003e [\n\t{\"jsonrpc\": \"2.0\", \"method\": \"api1.example.try\", \"id\": 1},\n   \t{\"jsonrpc\": \"2.0\", \"method\": \"api1.example.try-with-params\", \"params\": {\"foo\": \"bar\"}, \"id\": 2},\n\t{\"jsonrpc\": \"2.0\", \"method\": \"api1.example.garbage\", \"id\": 3}\n   ]\n\u003c- [\n\t{\"jsonrpc\": \"2.0\", \"result\": \"You've got it!\", \"id\": 1},\n   \t{\"jsonrpc\": \"2.0\", \"result\": \"Params received: $foo = bar.\", \"id\": 2},\n\t{\"jsonrpc\": \"2.0\", \"error\": {\"code\": -32601, \"message\": \"Method not found.\"}, \"id\": 3}\n   ]\n```\n\nAuthor: George Shestayev george.shestayev@gmail.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeorgique%2Fyii2-jsonrpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgeorgique%2Fyii2-jsonrpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeorgique%2Fyii2-jsonrpc/lists"}