Verb filters
When creating custom API endpoints, you may want to only allow certain HTTP verbs to be issued against these actions. For instance, a PUT request to an endpoint that deletes a user doesn't make much sense. One way to control which HTTP verbs can be executed against our actions is to use yii\filters\VerbFilter
. When using yii\filters\VerbFilter
, we simply need to specify which HTTP verbs will be accepted by each of our public actions. The following example shows the default verb filter that is used by yii\rest\ActiveController
:
public function behaviors() { return [ 'verbs' => [ 'class' => \yii\filters\VerbFilter::className(), 'actions' => [ 'index' => ['get'], 'view' => ['get'], 'create' => ['get', 'post'], 'update' => ['get', 'put', 'post'], 'delete' => ['post', 'delete'], ], ], ]; }