API Versioning Laravel

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
User avatar
MohammadShahriariFard
Posts: 3
Joined: 18 Jul 2021, 06:49

API Versioning Laravel

Post by MohammadShahriariFard » 18 Jul 2021, 07:06

Is there a way to versioning aimeos jsonapi & jsonadm?

currently, all web services working this way :

http://localhost:8000/jsonapi/attribute

The way I want is :

http://localhost:8000/jsonapi/v1/product

or :

http://localhost:8000/v1/jsonapi/product

I'm using the latest version of aimeos on Linux OS.

User avatar
aimeos
Administrator
Posts: 7873
Joined: 01 Jan 1970, 00:00

Re: API Versioning Laravel

Post by aimeos » 19 Jul 2021, 06:13

You can change the prefix for the jsonapi route in your ./config/shop.php:
https://github.com/aimeos/aimeos-larave ... op.php#L16
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
MohammadShahriariFard
Posts: 3
Joined: 18 Jul 2021, 06:49

Re: API Versioning Laravel

Post by MohammadShahriariFard » 19 Jul 2021, 11:43

aimeos wrote: 19 Jul 2021, 06:13 You can change the prefix for the jsonapi route in your ./config/shop.php:
https://github.com/aimeos/aimeos-larave ... op.php#L16
That was the easiest solution But it is not efficient at least in this case.
Because we may need several different versions, such as V1, V2, V3 in the future...
Should we create a separate extension for each version?
Should we add {version} parameter to the core route like below?

Code: Select all

			Route::match( array( 'GET' ), '{version}/{resource}', array(
			'as' => 'aimeos_shop_jsonapi_get',
			'uses' => 'Aimeos\Shop\Controller\JsonapiController@getAction'
		) )->where( ['site' => '[A-Za-z0-9\.\-]+'] );
Instead of :

Code: Select all

			Route::match( array( 'GET' ), '{resource}', array(
			'as' => 'aimeos_shop_jsonapi_get',
			'uses' => 'Aimeos\Shop\Controller\JsonapiController@getAction'
		) )->where( ['site' => '[A-Za-z0-9\.\-]+'] );
Given these conditions, what will be the structure of the directories and classes and route for supporting multi version API?
Considering that we need all versions because different parts of the project interact with all versions and we can not just have one version.

User avatar
aimeos
Administrator
Posts: 7873
Joined: 01 Jan 1970, 00:00

Re: API Versioning Laravel

Post by aimeos » 19 Jul 2021, 20:22

We don't change the JSON REST API in an incompatible way and therefore, we don't need versioning.

If you want to have different versions, you can add routes for each version pointing to different controller actions where you can use different implementations.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply