Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Why JSON API?

3,790 views

Published on

In this short presentation, Neel Prakash, Drupal Consultant, has discussed on JSON API, its advantages over Core REST API, Document Structure, HTTP methods, Request headers, Response codes and others.

The goal of this presentation is to bring you valuable information to help you in understanding JSON API. We hope you enjoy this post!
----------------------------------------------------------
Get Socialistic

Our website: http://valuebound.com/
LinkedIn: http://bit.ly/2eKgdux
Facebook: https://www.facebook.com/valuebound/
Twitter: http://bit.ly/2gFPTi8

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Why JSON API?

  1. 1. JSON API Neel Prakash https://www.drupal.org/u/neelproy
  2. 2. jsonapi module exposes a [JSON API]( http://jsonapi.org/ ) implementation for data stored in Drupal. About
  3. 3. ● 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:
  4. 4. 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 )
  5. 5. ● 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.)
  6. 6. 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
  7. 7. Accept: application/vnd.api+json Content-Type: application/vnd.api+json Request headers
  8. 8. 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
  9. 9. 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)
  10. 10. { "data": { "type": "node--article", "attributes": { "title": "Article1", "body": { "value": "Custom value", "format": "plain_text" } } } } 2. Creating new resources (POST)
  11. 11. URL: http://example.com/jsonapi/node/article/{{article_uuid}} { "data": { "id": "{{article_uuid}}", "attributes": { "title": "My updated title" } } } 3. Updating existing resources (PATCH)
  12. 12. 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)
  13. 13. Question ?
  14. 14. Thank you

×