JSON API
Neel Prakash
https://www.drupal.org/u/neelproy
jsonapi module exposes a [JSON API]( http://jsonapi.org/ )
implementation for data stored in Drupal.
About
● Minimizes number of requests and the amount of data transmitted
between client and server.
● Doesn't require any kind of configuration.
● Unlike core REST the JSON API is not simply a format like JSON or
HAL+JSON.The default format appears like:
`/jsonapi/{entity_type}/{bundle}/{uuid}?_format=api_json`
WHY JSON API ?
Advantages over Core REST API:
Document structure (core concept)
● Every request/response body must be underneath a single JSON
object.
{
// your data here...
}
● data - information specific to a resource.can be array( [ ] ) or object (
{ } ).
● type - entity type--bundle .( separated with hyphen - . eg. node--
article )
● attributes - store values specific to the resource.
● relationships - values that belong to another resource in the
system.(entity reference)
e.g. uid .(uid property is an entity reference to the
user that authored the article.)
Document structure…(contd.)
Specifies what HTTP Methods to accept.
1. GET - Retrieve data
2. POST - Create a new resource
3. PATCH - Update an existing resource
4. DELETE - Remove an existing resource
Note: PUT is not included.
HTTP methods
Accept: application/vnd.api+json
Content-Type: application/vnd.api+json
Request headers
Respond with the following codes:
● 200 OK - All successful GET and PATCH requests
● 201 Created - All successful POST requests (response
includes the newly
created resource)
● 204 No Content - All successful DELETE requests
Response codes
URL: http://d8.local/jsonapi/node/article
http://d8.local/jsonapi/node/article?sort=-nid
http://d8.local/jsonapi/node/article/?page[limit]=5
1. Fetching resources (GET)
{
"data": {
"type": "node--article",
"attributes": {
"title": "Article1",
"body": {
"value": "Custom value",
"format": "plain_text"
}
}
}
}
2. Creating new resources (POST)
URL: http://example.com/jsonapi/node/article/{{article_uuid}}
{
"data": {
"id": "{{article_uuid}}",
"attributes": {
"title": "My updated title"
}
}
}
3. Updating existing resources
(PATCH)
URL: http://example.com/jsonapi/node/article/{{article_uuid}}
● Enable "HTTP Basic Authentication" drupal module.
● Response: HTTP 204 (No content) response.
4.Removing existing resources
(DELETE)
Question ?
Thank you

Why JSON API?