Laravel-json-api: Route prefix issue?

Created on 17 Jun 2017  路  3Comments  路  Source: cloudcreativity/laravel-json-api

Hey, first of all, thank you for this wonderful package! I went through all HAL/JSON-API/JSON-LD packages for Laravel and this was the only one that really abide by the JSON API standards really well.

So I've got a minor issue here.

This is my route file under routes/api.php. I might have done something that is not 'correct' to work well with your package.

/**
 * API v1
 */
Route::group([
    'namespace' => 'Api\V1',
    'prefix' => 'v1'
], function () {
    JsonApi::api('v1', ['as' => 'api.'], function ($api, $router) {
        $api->resource('users');
    });
});

I also tried this:

JsonApi::api('v1',
    [
        'namespace' => 'Api\V1',
        'prefix' => 'v1',
        'as' => 'api::'
    ], function ($api, $router) {
        $api->resource('users');
    });

And in the config/json-api-v1.php file, I've also set this:

    /*
    |--------------------------------------------------------------------------
    | URL Prefix
    |--------------------------------------------------------------------------
    |
    | The URL prefix to be used when encoding responses. Use this if
    | your API is hosted within a URL namespace, e.g. `/api/v1`.
    |
    | Although we could detect this for HTTP requests, we need it defined here
    | for when we are encoding outside of HTTP requests, e.g. broadcasting.
    |
    */
    'url-prefix' => '/api/v1',

When I send a GET request to http://127.0.0.1:8000/api/v1/users, I get this output.

{
    "data": [
        {
            "type": "users",
            "id": "a6137b2c-6fca-3cde-9b12-07ba976e7f86",
            "attributes": {
                "created-at": "2017-06-17T18:07:44+00:00",
                "updated-at": "2017-06-17T18:07:44+00:00",
                "name": "Justen Mann",
                "email": "[email protected]"
            },
            "links": {
                "self": "/users/a6137b2c-6fca-3cde-9b12-07ba976e7f86"
            }
        }
    ]
}

Here's the problem -- under data[0].links.self, "self": "/users/a6137b2c-6fca-3cde-9b12-07ba976e7f86", the link does not include the prefixed api/v1. How do I fix this? Or is this somewhat intentional?

bug

Most helpful comment

Thanks for reporting this bug. Just tagged v0.9.1

All 3 comments

@GIANTCRAB thanks for the feedback and glad you're finding the package useful!

This looks like a bug from an initial glance. I'll investigate and get back to you after the weekend.

I'm experiencing exactly the same problem.

Thanks for reporting this bug. Just tagged v0.9.1

Was this page helpful?
0 / 5 - 0 ratings