You are here

function rest_server_response_formatters in Services 6.3

Same name and namespace in other branches
  1. 7.3 servers/rest_server/rest_server.module \rest_server_response_formatters()

Builds a list of response formatters that are available to the RESTServer.

Return value

array An associative array of formatter info arrays keyed by type extension. The formatter info specifies an array of 'mime types' that corresponds to the output format; a 'view' class that is a subclass of RESTServerView; and 'view arguments' that should be passed to the view when it is created; a 'model' can also be specified which the controller then must declare support for to be able to serve data in that format.

2 calls to rest_server_response_formatters()
RESTServer::responseFormatters in servers/rest_server/includes/RESTServer.inc
rest_server_setup_settings in servers/rest_server/rest_server.module
Set up settings for a rest server endpoint, fills the settings array with defaults. This is done to ensure that the default state is consistent between what's shown by default in the settings form and used by default by the REST server if it…

File

servers/rest_server/rest_server.module, line 90

Code

function rest_server_response_formatters() {
  static $formatters = NULL;
  if (!$formatters) {
    $formatters = array(
      'xml' => array(
        'mime types' => array(
          'application/xml',
          'text/xml',
        ),
        'view' => 'RESTServerViewBuiltIn',
        'view arguments' => array(
          'format' => 'xml',
        ),
      ),
      'json' => array(
        'mime types' => array(
          'application/json',
        ),
        'view' => 'RESTServerViewBuiltIn',
        'view arguments' => array(
          'format' => 'json',
        ),
      ),
      'jsonp' => array(
        'mime types' => array(
          'text/javascript',
          'application/javascript',
        ),
        'view' => 'RESTServerViewBuiltIn',
        'view arguments' => array(
          'format' => 'jsonp',
        ),
      ),
      'php' => array(
        'mime types' => array(
          'application/vnd.php.serialized',
        ),
        'view' => 'RESTServerViewBuiltIn',
        'view arguments' => array(
          'format' => 'php',
        ),
      ),
      'bencode' => array(
        'mime types' => array(
          'application/x-bencode',
        ),
        'view' => 'RESTServerViewBuiltIn',
        'view arguments' => array(
          'format' => 'bencode',
        ),
      ),
      'rss' => array(
        'model' => 'ResourceFeedModel',
        'mime types' => array(
          'text/xml',
        ),
        'view' => 'RssFormatView',
      ),
    );
    if (_rest_server_get_spyc_location() !== false) {
      $formatters['yaml'] = array(
        'mime types' => array(
          'text/plain',
          'application/x-yaml',
          'text/yaml',
        ),
        'view' => 'RESTServerViewBuiltIn',
        'view arguments' => array(
          'format' => 'yaml',
        ),
      );
    }
    drupal_alter('rest_server_response_formatters', $formatters);
  }
  return $formatters;
}