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_jsonThis 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.