Last updated February 25, 2016. Created on September 23, 2013.
Edited by kay_v, Wim Leers, bigjim, likewhoa. Log in to edit this page.

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

AttachmentSize
dev-http-client.png329.03 KB
DHC_by_Restlet.png136.9 KB

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.