Hello,
I need to implement some json-rpc apis in my project, and i thought to use phalcon for this too as it is very nice and powerful tool. So, what's the difference between usual Phalcon\Mvc\Micro examples and JsonRPC? Difference is how controller and action names and request parameters are taken.
For usual applications we take controller, action names from GET and parameters both from GET and POST. For JsonRPC applications we need to grap controller and action names from jsonrpc object, that is placed in raw post data:
For following request we should retrieve controller RobotController, action createAction() and params [type => standard, color => red]
{
"jsonrpc": "2.0",
"method": "robot.create",
"params": {
"type" : "standard",
"color" : "red"
},
"id": 1
}
How we can achieve this?
First of all, i looked though Phalcon\Mvc\Router code, docs: https://docs.phalcon.io/en/latest/api/Phalcon_Mvc_Router.html code: https://github.com/phalcon/cphalcon/blob/master/ext/mvc/router.c#L392
Router is responsible for retrieving controller name, action name and parameters. Obviously, this operation is performed in router->handle() method.
Please correct me if i am wrong, router does not use http request object to retrieve controller name, controller action and parameters, it takes them directly from uri, etc. From my point of view, it could be more flexible if router::handle could accept request object with parameters. This way we would be able to inject jsonrpc request with all parameters to router instead of default http request.
For a moment perhaps i am missing something - please correct me if i am wrong. If need to implement such jsonrpc support, do i need to re-define router class and handle() method? It contains lots of code, and i definetely don't want to re-define it.
Perhaps there is another way for easy and painless implementation?