Hi,
I defined two versions of the API (v1 and v2). Default version is v2. How can I call actions from version 1? I tried with url: http://some_address/api/v1/action_name but it gives me 404 error.
If you look at the documentation he shows how you can specify a version in the header:
https://github.com/dingo/api/wiki/Making-Requests-To-Your-API
As far as the version being specified in the URL, all the issues I've seen that request this have been shut down by preference. I've written a "hack" that has worked out so far:
$api->version(['v1'], function($api) {
$api->get('/{version}/{call}/', function($version,$call) {
return app('Dingo\Api\Dispatcher')->version($version)->get($call,$_REQUEST);
});
});
I'm sure this can be improved, but so far it has been working well for me
Interesting hack, I was using this..
DingoRoute::version(['v1'], [], function(){
DingoRoute::group(['prefix' => 'v1', 'namespace' => 'App\Http\Controllers\Api\V1'], function() {
// routes of v1 i.e.:
DingoRoute::resource('users', 'UsersController');
});
});
By design of the package, you'd want to change the version in the Accept header, to make a request to say v1, if your default is v2. The setup @isometriq is using allows you to have the version in both the URL and the Header, but then you are basically doubling up the versioning logic.
Would personally say to just use the header approach and not include the version in the URL, but obviously thats a matter of preference.
Definitely use proper content negotiation.
If you want to put a version in the URL you can but you need to manage it yourself. Simply specifying a prefix like @isometriq is the easiest way to achieve this.
@jasonlewis why make an API package that restricts the style of how things are done to their liking, especially if you're not following a spec and just letting preference overrule, it doesn't hurt to allow the package to support it.
There's a LOT of articles out there that discuss the pros and cons of all methods involved with versioning APIs.
Content negotation is by far the best method available and Dingo does all the work required so you don't need to worry about anything, just send the appropriate header.
I really see no point in adding this as you can just add the prefix to your route group yourself. This saves having to have a configuration option or something and I would honestly just prefer it if folks would use content negotation.
This is so stupid that you can't route version just by URL and version header is always required.
Using version header must be optional.
Most helpful comment
@jasonlewis why make an API package that restricts the style of how things are done to their liking, especially if you're not following a spec and just letting preference overrule, it doesn't hurt to allow the package to support it.