Skip to content

About response formatters

jeff-h edited this page Dec 15, 2015 · 3 revisions

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.

Selecting a formatter

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

Custom formatters are possible by extending one of the formatter classes from restful/src/Plugin/formatter

Clone this wiki locally