Alternative way to pass params to target action
Pre-release
Pre-release
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!