An overview of JSON API in Drupal for beginners
This JSON API tutorial is aimed at beginners to introduce them to the open standard format. Let’s check out the advantages of JSON over RESTful Web Services:
To mention a few:
- It reduces both the number of requests and the amount of data transmitted between clients and servers.
- Unlike core REST module, JSON API is Zero configuration Drupal module.
- By enabling the JSON API module, you can immediately gain a full REST API for every type in your Drupal application.
- JSON API inspects entity type and bundle to provide URLs to access each one of them using the standard HTTP methods, GET, POST, PATCH, and DELETE
- It controls which HTTP methods should be used, what HTTP response codes should be returned under specific request, the format of the response body, and the link between resources.
HTTP methods in Drupal
HTTP enables communication between clients and servers. JSON API supports GET, POST, PATCH and DELETE HTTP methods in Drupal.
1. Fetching resources (GET)
A web request using GET method is made only to retrieve data from a given resource. One can make web request either through the browser or any other HTTP client (e.g. Postman chrome app).
2. Creating new resources (POST)
Submit data to a server to create a new content.
3. Updating existing resources (PATCH)
PATCH method submits data to a server to update an existing content.
4. Removing existing resources (DELETE)
DELETE method is used to request the server to delete a specific content.
JSON is a way to store information in an organized way as it gives a human-readable collection of data that we can access in a logical manner. Try JSON on your website to find out what works better for your project.