- First, we must add the JSON API module to our Drupal site:
cd /path/to/drupal8
composer require drupal/jsonapi
- Install the JSON API and Serialization module. Once the module is installed, the API endpoints will be active.:
- To perform a request, you must pass an Accept header with the value application/vnd.api+json.
- For the JSON API specification, every resource must have a unique type name, and JSON API derives this from the entity type and its bundle. The endpoint for retrieving Article nodes will be:
http://127.0.0.1:8888/jsonapi/node/article
- The entire request can be executed with the following command:
curl -X GET \
http://127.0.0.1:8888/jsonapi/node/article \
-H 'accept: application/vnd.api+json'
- The response will resemble the following. The content values will be in the attributes property:
{
"data": [
{
"type": "node--article",
"id": "c897acba-eb81-454a-94ed-13107fd205cf",
"attributes": {...},
"relationships": {...},
"links": {
"self": "http://127.0.0.1:8888/jsonapi/node/article/c897acba-eb81-454a-94ed-13107fd205cf"
}
}
],
"links": {
"self": "http://127.0.0.1:8888/jsonapi/node/article",
}
}