How can I access REST endpoints with the path /api/v1/controller/action?

My folder structure for the API files goes as follows:

  • api
    • common
      • controllers
      • models
    • v1
      • controllers
      • models
      • Module.php

In my config file I have the module registered as:

'modules' => [
    'api/v1' => [
        'class' => 'app\api\v1\Module',
    ],
]

I have my url rules registered as:

'urlManager' => [
        'enablePrettyUrl' => true,
        'enableStrictParsing' => true,
        'showScriptName' => false,
        'rules' => [
            ['class' => 'yii\rest\UrlRule', 'controller' => ['api/v1/user', 'api/v1/application', 'api/v1/flag', 'api/v1/role']],
        ],
    ]

However, when I make a GET request to /api/v1/users it gives a 404, when presumably according to the docs it should return JSON as if an /index controller action was accessed. Do controllers need to implement the code to get the data and return it, or is it done automatically?

This is my workaround so far. I renamed the module to v1 from api/v1. And then I set this URL rule: 'api/<version:v\d+>/<controller:[\w-]+>' => '<version>/<controller>', which will hit endpoints defined in this ruleset here: ['class' => 'yii\rest\UrlRule', 'controller' => ['v1/user', 'v1/application', 'v1/flag', 'v1/role']].