In general, you need to make a module on yii2 that will work as RestFull. Here is part of the configuration

'urlManager'=>[ 'enablePrettyUrl' => true, 'enableStrictParsing' => true, 'showScriptName' => false, 'rules' => [ ['class' => 'yii\rest\UrlRule', 'controller' => ['v1/books','v1/authors']], ], ], 

But with this configuration, simple routing does not work all over the site.

    1 answer 1

    Here is an example of my working config:

      'urlManager' => [ 'enablePrettyUrl' => true, 'enableStrictParsing' => true, 'showScriptName' => false, 'rules' => [ '' => 'site/index', 'GET v0/<controller:\w+>/<id:\w+>.<_format>' => 'v0/<controller>/view', 'GET v0/<controller:\w+>.<_format>' => 'v0/<controller>/index', 'v1/<controller:[\w\-]+>/<id:[\w\d\-]+>.<_format>' => 'v1/<controller>/view', 'v1/<controller:[\w\-]+>.<_format>' => 'v1/<controller>/index', ], ],