Problem/Motivation

Follow-up from #2880987: Fix failing tests with PHP7 / D8.4.x in the dev branch.

At the moment if there is no Accept: application/vnd.api+json header sent from a client, request is being treated as html internally by Drupal. It didn't cause any issues until #2293697: EntityResource POST routes all use the confusing default: use entity types' https://www.drupal.org/link-relations/create link template if available was implemented and merged into 8.4.x core. As soon as Drupal core got handler for 4xx pages, all html requests which throw 4xx errors have started returning html response (which essentially does make sense and not a bug). It means that now client apps have to explicitly specify Accept: application/vnd.api+json in order to get guaranteed response in json format. Otherwise there's a chance that they will get response as html. So far it's just locked to errors, but we never know how things might change in the future. So it makes sense to enhance JSON API documentation to let devs know about this mandatory request header.

Proposed resolution

1. Update all request examples in the documentation to include Accept: application/vnd.api+json header.
2. It should be mentioned somewhere that starting from Drupal 8.4.x without this header all errors will return html instead of json.

Comments

Spleshka created an issue. See original summary.

clemens.tolboom’s picture

Assigned: Unassigned » clemens.tolboom
clemens.tolboom’s picture

Assigned: clemens.tolboom » Unassigned

This is already on https://www.drupal.org/docs/8/modules/json-api/api-overview

I've edited all pages worth editing. Hope I didn't missed one.

As we now have updated all example pages I don't think we should mention this 8.4.x as to me it is a user error NOT to use the Accept header.

spleshka’s picture

Status: Active » Fixed

Sounds good to me, thanks @clemens.tolboom. Also documentation changes look good as well. Great job! :)

wim leers’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.