StateLess
StateLess

Reputation: 5402

Handling routes in laravel

I have api with two different versions v1 and v2 both of them have same end points. But the way i handle sessions is different, what will be the clean way of handling routes file and to know which api version user is using. I am using laravel 4.1

Example routes:

/v1/getsome/1
/v2/getsome/1

Thanks in advance

Upvotes: 0

Views: 51

Answers (2)

brokekidweb
brokekidweb

Reputation: 157

Use the version as a parameter in your route, then handle the version in your controller.

    Route::get('getsome/{id}/{version}/', 'APIController@getsome()')->where('version', '[1-2]+');

Upvotes: 0

Damien Pirsy
Damien Pirsy

Reputation: 25435

v1/v2 can easily be a placeholder,so in the future you could change/increase the versioning without breaking the api

Route::get('{version}/getSome/{id}', ['as' => 'getstome', 'uses' => 'controller@method');

And then you handle the version in the cotnroller's method.

Or you could use a prefix (I'd prefer this), so you don't need to specify the version in your routes:

Route::group(['prefix' => 'v1'], function(){
  Route::get('getsome/{id}', ....);
};

Upvotes: 1

Related Questions