Warning message

Documentation is currently being migrated into the new system. Some pages might be temporarily missing, and some guides might appear empty. Thank you for your patience while we are improving Drupal.org documentation.

2. GET for reading content entities

Last updated on
9 November 2016

Follow these steps to expose resources to GET requests:

  1. Configuration
  2. Test with a GET request

Configuration

See Getting started: REST configuration & REST request fundamentals — Configuration

Sample requests below assume this configuration:

resources:
  entity:node:
    GET:
      supported_formats:
        - hal_json
      supported_auth:
        - basic_auth
        - cookie

Test with a GET request

You can use many clients to test requests.

cURL

curl http://example.com/node/1?_format=hal_json

Guzzle

$response = \Drupal::httpClient()
  ->get('http://example.com/node/1?_format=hal_json', [
    'auth' => ['username', 'password'],
  ]);

$json_string = (string) $response->getBody();

jQuery

jQuery.ajax({
  url: 'http://example.com/node/1?_format=hal_json',
  method: 'GET',
  success: function (comment) {
    console.log(comment);
  }
});

Dev HTTP Client

An easy way to test is using a browser extension such as Dev HTTP Client. This exposes options for all of the HTTP headers that you may need to use.

GET request with Dev HTTP client