Routing API Versions

Hello there!

I’m trying to set up a version control for my api. Originally, I followed the bravo-kernel tutorial for setting up an API, but now I want to extend it with version control.

In routes.php I used prefix-routing to the namespace/directory “api”. In that dir, all controllers are stored. Now I want to change the routing in that way, that I call /api/v2/users/. This should map to the api namespace, to the same controllers but with a method-suffix _v2 like “index_v2”. So I have one controller for all API-Versions but with suffixed-methodnames. Does this make sense or should it completly separeted?

Therefore, I tried to have single connect-method in the routes.php api-scope like
Router::connect(’/:version/:controller’, [‘controller’ => ‘:controller’, ‘action’ => ‘:action_:version’, ‘prefix’ => ‘api’]);
but this doesn’t work. I don’t know how to set up the router for my use case. In general, routing is relatively new to me, so please help me.

Thanks in advance!

I would strongly suggest to you to take a look here https://www.cakedc.com/jorge_gonzalez/2016/12/02/cakephp-api-plugin and then continue here https://github.com/CakeDC/cakephp-api/tree/master/docs/Documentation

Thanks for your answer. Didn’t know about this plugin.

I just used CakePHP-REST-API with CRUD and JWT for Authorization just like the bravo-kernel tutorial. This also works well, despite of the routing. I’ll investigate in the routing-topic again and also in the suggested plugin.

If there are any further hint regarding the routing questions, please tell me.

Thanks