Releases: georgique/yii2-jsonrpc
Mate
Rooibos
Oolong
This release contains:
- Serializer . Idea is based on Yii2 native REST serializer, but it's adapted for the Json RPC protocol.
- Improved error handling. Now JsonRpcError has data property, which goes error.data property in response. Besides that, error.data will contains the following:
- exception - original exception
- human_message - message which you can show on the client-end directly to user. By default comes from the PREVIOUS exception message, so if you throw any exception in an action, it's message will go here.
- error_code - original error code. Same approach as with human_message, goes from PREVIOUS exception, gives ability to react on errors better on a client side.
Earl Grey
Hotfix
Black Tea
Alternative way to pass params to target action
Sometimes, there can be a lot of params sent within json-rpc request, e.g. model attributes for it's creation. In order to not list all of them as action arguments, an alternative way to pass params is introduced. Now an entry point can be customized, and params will be passed to target action as Yii request body params (see README).
Also now method-to-action translation involves UrlManager, so following requests are possible now:
{"jsonrpc": "2.0", "method": "api1.user.2.update", "params": {"email": "updated-email@example.com"}, "id": 1}
With the customized entry point you can easily have the following action:
public function actionUpdate($id) {
$model = $this->findModel($id);
if (!$model) {
throw new NotFoundHttpException('Requested model not found.');
}
$model->setScenario($this->updateScenario);
$model->load(Yii::$app->getRequest()->getBodyParams(), '');
if ($model->save()) {
return $model;
} elseif (!$model->hasErrors()) {
throw new ServerErrorHttpException('Failed to update the object for unknown reason.');
}
return $model;
}
If that doesn't look familiar - it's just typical UPDATE action from Yii2 REST module. Voi la!
First beta release
Extension is tested and works well. There are still some improvements to be done, but it is now in usable (not PRODUCTION yet though) condition.
Critical fix for exception handling
1.0-alpha.2 had a critical bug leading to an empty response instead of correctly rendered error. Fixed in this one.
Better exception handling
This release moves extension closer to the stable state, but still far from it as it is not well tested. Exception handling was improved since the previous alpha and initial successful tests were done.