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
Comment #2
clemens.tolboomComment #3
clemens.tolboomThis 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.
Comment #4
spleshkaSounds good to me, thanks @clemens.tolboom. Also documentation changes look good as well. Great job! :)
Comment #5
wim leersHmmm… I think this has been the case ever since #2831137: Remove the need for ?_format=api_json: assume the use of the 'api_json' format for routes managed by JSON API in JSON API, not since #2293697: EntityResource POST routes all use the confusing default: use entity types' https://www.drupal.org/link-relations/create link template if available in Drupal core?
Let's get e0ipso's feedback before closing this.
Comment #6
wim leersPer #2880987-22: Fix failing tests with PHP7 / D8.4.x in the dev branch.
Comment #7
spleshkaYes, this is correct. Though it became a noticable problem since #2293697: EntityResource POST routes all use the confusing default: use entity types' https://www.drupal.org/link-relations/create link template if available.