Andrew Fletcher published: 19 May 2022 1 minute read
For an introduction into setting up RESTful hal+json refer to the set-up documentation.
GET a node
To get the content of the specific node you require the node.nid. The key information required in the GET query:
- URL - your-site.com/node/<nid>?_format=hal_json;
- Content-Type - application/hal+json;
- Nod.nid - noted in the URL string as <nid>.
Example using a node.nid of one (1). So the nid in the URL is <nid> = 1
your-site.com/node/1?_format=hal_json
This get on the staging site will output the following:
{
"nid":[{"value":"1"}],
"uuid":[{"value":"c5ab1e63-0b72-4325-bfe6-5c77d3a7acd4"}],
"vid":[{"value":"1"}],
"langcode":[{"value":"en"}],
"type":[{"target_id":"page","target_type":"node_type","target_uuid":"078109da-c606-4810-b684-d3c059eb3aab"}],
"title":[{"value":"Posting to your site using REST API"}],
"uid":[{"target_id":"2","target_type":"user","target_uuid":"f000c9a3-82b2-4ef7-92bb-786f00863c66","url":"\/user\/2"}],
"status":[{"value":"1"}],
"created":[{"value":"1467305369"}],
"changed":[{"value":"1467305390"}],
"promote":[{"value":"0"}],
"sticky":[{"value":"0"}],
"revision_timestamp":[{"value":"1467305390"}],
"revision_uid":[{"target_id":"2","target_type":"user","target_uuid":"f000c9a3-82b2-4ef7-92bb-786f00863c66","url":"\/user\/2"}],
"revision_log":[],
"revision_translation_affected":[{"value":"1"}],
"default_langcode":[{"value":"1"}],
"path":[],
"body":[{"value":"<p>Lear how to POST via REST to Drupal your site.<\/p>\r\n","format":"basic_html","summary":""}]
}
Testing through Chrome
Using the Chrome extension DHC, enter the parameters noted above as a means of cross checking and testing.
Related articles
Andrew Fletcher
•
19 Apr 2024
Extending a Contrib Module's Configuration in Drupal 10: A Case Study with Sitewide Alert
Extending the functionality of a contrib module in Drupal can enhance its usefulness without altering the original codebase. This article provides a step-by-step guide on how to add custom configuration options to an existing contrib module, using the sitewide_alert module as an example. We will...
Andrew Fletcher
•
18 Apr 2024
LogicException: Form errors cannot be set after form validation has finished
When receiving a logic error such asLogicException: Form errors cannot be set after form validation has finished. in Drupal\Core\Form\FormState->setErrorByName() (line 1104 of /var/www/html/project/core/lib/Drupal/Core/Form/FormState.php).This error "LogicException: Form errors cannot be set...
Andrew Fletcher
•
09 Apr 2024
Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
Adding a new service to a custom module and the following error greeted me:The website encountered an unexpected error. Try again later.
Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service "summaries.reference_node". in...