Framework: JSON API and "Content-Type: application/vnd.api+json" / "Accept: application/vnd.api+json"

Created on 25 Sep 2015  路  2Comments  路  Source: laravel/framework

The new JSON API spec (http://jsonapi.org/format/) specifies that "Clients MUST send all JSON API data in request document with the header Content-Type: application/vnd.api+json..." and "Servers MUST send all JSON API data in response documents with the header Content-Type: application/vnd.api+json"...

However, currently in Illuminate/Http/Request.php, the isJson() method looks for "/json", and several other methods look for "application/json" in these headers. Thus, content served via the JSON API spec won't be interpretted as JSON currently via Laravel/Lumen.

Most helpful comment

Accept: application/vnd.api+json should return false for accepts json, because it doesn't...

You can't return any kind of json response, it specifically must be application/vnd.api+json

All 2 comments

You could overwrite the isJson() in your app/Http/Requests/Request.php like this:

public function isJson()
{
    return \Illuminate\Support\Str::contains($this->header('CONTENT_TYPE'), ['/json', '+json']);
}

Accept: application/vnd.api+json should return false for accepts json, because it doesn't...

You can't return any kind of json response, it specifically must be application/vnd.api+json

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RomainSauvaire picture RomainSauvaire  路  3Comments

ghost picture ghost  路  3Comments

YannPl picture YannPl  路  3Comments

Fuzzyma picture Fuzzyma  路  3Comments

Anahkiasen picture Anahkiasen  路  3Comments