I am using Laravel 5 and building web service for an application which needs api versioning. This is the folder structure I found so far in different web resources
/app
/controllers
/Api
/v1
/UserController.php
/v2
/UserController.php
The problem is there are many functions in the UserController
that most likely will be unchanged among versions or any change might be applied to every version. For example there is an logout
function which sends a message to user after logout. If I copy this function in every UserController
, then any minor change, say changing the message or anything like that, makes me to change every UserController
in different versions. As a result I decided to create a BaseUserController
and insert the shared functions in there and every Usercontroller
should inherit this. I mean this
/app
/controllers
/Api
/BaseUserController.php extends Controller.php
/v1
/UserController.php extends BaseUserController.php
/v2
/UserController.php extends BaseUserController.php
so if any version needs to implement its own logout
, simply it overrides its parent function or for any global change, I change the function in the parent.
I would like to ask you, is this a good strategy to implement api versioning? and what is the problem with this?
Thanks in advance
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire