How to Setup Drupal 8.x site for web services, rest API using JSON API module.
From below instructions, We able to setup Drupal 8.x site as web services for rest API using JSON API and REST module.
As we know the Drupal can be use as a powerful backend CMS. So for that we have to setup our Drupal environment to use it as web services rest API.
So, we can achieve it by using JSON API module providing in Drupal 8.x
If anyone interested in using Drupal as backend system and having a question in mind that “Is it possible to use Drupal only as a backend?” The Answer is Yes.
What is JSON:API in Drupal 8.x?
Specification for how a client should request that resources be fetched or modified, and how a server should respond to those requests.
JSON:API is designed to minimize both the number of requests and the amount of data transmitted between clients and servers. This efficiency is achieved without compromising readability, flexibility, or discoverability.
If you don’t know that how to setup and use Drupal site as rest API, then you are on a right place.
So these are step by step easy guide to setup JSON API rest API in Drupal 8.x 🙂
1. Login to your Drupal 8 site then Go to Extend and scroll down to the bottom of the page. Install and enable all the modules under Web Services section.
2. Now we have to install and enable another module which provides us a user interface for configuring web services rest modules easily.
The module is Rest UI
To install the module just go to Rest UI module page mentioned above and copy the link or address location for tar.gz file and paste it inside Install new module.
Then simply to enable it go to Extend -> Web services section and enable REST UI module
Awesome, Our basic structure to setup rest API’s and use our Drupal 8.x site as web services using JSON API module has been done.
3. After setup, let’s configure the JSON API module.
Go to Configuration -> Web services then JSON:API and Configuration JSON API module for your desired operations.
4. Now, have a look at configurations of the REST module.
Go to Configuration -> Web services -> REST
Here we can manage REST modules easily, By default Content REST resource is enabled for All operations.
NOTE: To use other operations like POST, PATCH and DELETE make sure to set allowed operation types inside JSON:API configuration as mentioned above.
Finally the good news, we are all done and ready to do test with our first rest API for using Drupal 8.x site as web services.
We are going to test Login and Logout API’s by using Postman API testing tool.
Login rest API
In Response we will get some user information, csrf_token and logout_token
CSRF token will be use later for authentication purposes.
Logout token will have to send when we do logout rest API.
Logout rest API
NOTE: Pass Logout token which we get in Login API response as URL parameter
Congratulations now we can user our Drupal 8.x site as web services via rest API’s using JSON API and REST module 🙂