-
Notifications
You must be signed in to change notification settings - Fork 173
About response formatters
RESTful abstracts the code that generates the final response output into response formatters.
RESTful v2.x introduced a new default formatter, JSON-API. There are numerous 3rd-party implementations of JSON-API for many API-consuming technologies e.g. Angular, Backbone, Ember (as well as iOS, Ruby, PHP etc). See http://jsonapi.org/implementations These implementations may provide a good head-start in consuming RESTful's JSON-API responses from your chosen front-end framework/language.
At admin/config/services/restful
you can specify which formatter RESTful should use by default.
However, requests may specify a specific formatter by sending the Accept
header.
For example, to request JSON-API:
Accept: application/vnd.api+json; charset=utf-8
The correct Accept
header to send can be found in the corresponding formatter class. For the above example this would be restful/src/Plugin/formatter/FormatterJsonApi.php
which defines on line 41 the following:
protected $contentType = 'application/vnd.api+json; charset=utf-8';
Custom formatters are possible by extending one of the formatter classes from restful/src/Plugin/formatter