php - Laravel RESTful API versioning design -


i new laravel (4 , 5) , working on restful api. in order allow multiple version of api, using url determine version.

i read follow post , seem people following approach: how organize different versioned rest api controllers in laravel 4?

folders structures:

/app   /controllers     /api       /v1         /usercontroller.php       /v2         /usercontroller.php 

and in usercontroller.php files set namespace accordingly:

namespace api\v1; 

or

namespace api\v2; 

and in routes:

route::group(['prefix' => 'api/v1'], function () {   route::get('user',      'api\v1\usercontroller@index');   route::get('user/{id}', 'api\v1\usercontroller@show'); });  route::group(['prefix' => 'api/v2'], function () {   route::get('user',      'api\v2\usercontroller@index');   route::get('user/{id}', 'api\v2\usercontroller@show'); }); 

url simple http://..../api/v1 version 1 , http://..../api/v2 version. straight forward.

my questions is: if building minor upgrade of api, v1.1 , how organize folder structure? thought , should still fine dot valid name of folders?

/app   /controllers     /api       /v1         /usercontroller.php       /v1.1         /usercontroller.php       /v1.2         /usercontroller.php       /v2         /usercontroller.php 

also, how should write namespace? no namespace

namespace api\v1.1; 

is there naming convention can refer using "dot" ?

note: not want call version v2 because not major upgrade.

imo, minor upgrades should not publish breaking changes api. suggestion stick integer versioned apis. enhancements no problems, existing endpoints should behave usual.

this way api-versions in sync route-prefixes , namespaces tests.

example

  1. you begin v1.0
  2. you make little change (eg. git-tag v1.1) not bring breaking changes api. there need developers else in code? no, there not. can safeley let uri-prefix stay @ v1, developers calling api not need change code calling api (and therefore, automatically benefit new minor version). maybe fixed bug, makes code behave expected or published new feature, self not break existing feature-calls.
  3. your app grows , publish new redesigned version of api contains breaking changes. in case, publish new api-uri-prefix (v2).

be aware can of course keep track of minor versions internally (e.g in scm), there should no need developers change of api-calls benefit little bugfix published. anyways, nice of course if notify clients of newer minor versions , bugfixes or enhancements offer (blog, newsletter, ..)

let me add, not aware of restful apis minor api-url-prefixes, guess quite common practice.


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -