Follow these steps to expose resources to GET requests:
First make sure that REST module is enabled.
You may skip the steps below as by default all operations on entity:node are enabled. Below are the steps needed if you want to fine-tune your settings.
- Copy all of the files in your active config directory to your staging directory
- Make the needed changes to your rest.settings.yml file as shown below
- Go to admin/config/development/configuration to sync the configuration
- Clear caches
# Example configuration for enabling REST resources.
# Enable the node resource.
# Enable the taxonomy term resource.
Go to /admin/people/permissions#module-rest and grant the corresponding REST permission to a user role you would like to be able to access the resource. Note: entity and field access still applies on top of that.
This can also be done with drush:
drush role-add-perm anonymous 'restful get entity:node'
Test with a GET request
You can use many clients to test requests.
curl -H "Accept: application/hal+json" --request GET http://drupal-8.localhost/node/1
use Guzzle\Http\Client; $client = new Client('http://drupal-8.localhost');
// If in a Drupal environment use the HTTP client service.
$client = Drupal::httpClient()->setBaseUrl('http://drupal-8.localhost'); $request = $client->get('node/1');
$response = $request->send()->json();
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.
UPDATE: Url has changed from 'mysite.com/entity/node/1' to 'mysite.com/node/1'