Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dingo API - How to add version number in url?

I have just installed Dingo and it appear to work with the following URL:

http://website.dev/api/test

http://website.dev/api/hello

$api = app('Dingo\Api\Routing\Router');
    $api->version('v1', function ($api) {

        $api->get('test', function () {
            return 'Test';
        });

        $api->get('hello', function () {
            return 'Hello';
        });

    });

I would like version v1 to be included in the URL, how do I get this to work? When I try:

http://website.dev/api/v1/test

I get error:

{
"message": "404 Not Found",
"status_code": 404
}

In the .env file, I have: API_PREFIX=api

According to Dingo Configuration:

Avoid putting a version number as your prefix or subdomain as versioning is handled via the Accept header.

like image 733
I'll-Be-Back Avatar asked Oct 15 '25 04:10

I'll-Be-Back


1 Answers

The version of dingoAPI don't work this way. Because they aren't versioning the API in the URI, you need to define an Accept header to request a specific version. The header is formatted like so:

Accept: application/vnd.YOUR_SUBTYPE.v1+json

For accessing the version you will need a HTTP Client like postman

like image 135
rat Avatar answered Oct 17 '25 18:10

rat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!