How To Expose Modules In Drupal 9

A few times ago, the Drupal community made architectural changes that offered modern techniques for developers to build digital experiences. REST API was one of them, and the change was made in core. 

A RESTful API conforms to the architectural style of REST. This API accesses and uses data via HTTP requests to GET, POST, PUT, and DELETE data types. 

If you’re new to Drupal and don’t know how to expose modules in Drupal 9, this article is for you. So let’s discuss it in detail!

Also Read: Why Should You Prefer On-Going Support And Maintenance For Your Drupal Website?

Which HTTP methods are used in REST API? 

Here is a list of HPPT methods that are used in REST API: 

  • GET: It is used to read data from a server
  • POST: To create data on a server
  • PATCH: To update any data on a server
  • DELETE: To delete data from a server

Initially, the client uses HTTP methods to send the request. Then, REST API interacts with the database and sends the response in JSON or XML formats.

Also Read: How To Make Multilingual Website Using Drupal 9?

Drupal Modules to Expose your API

Here are some Drupal core and contributed modules that help expose APIs in Drupal 9: 

  • HTTP Basic Authentication – The HTTP basic authentication module offers controlled access to API resources based on the HTTP method with the help of an authentication plugin. 
  • RESTful Web Services – The RESTful web services module manages the resources plugin system. It also defines initial resource routes. Finally, the Resource plugin retrieves the data from the database.
  • Serialization – The serialization module deserialize and serialize request response data.
  • REST UI – Rest UI exposes RESTful web services configuration via the admin UI, allowing you to configure API endpoints by editing the YML files.

Also Read: How To Build Marketing Landing Pages With Drupal 9?

How Does The REST Response Works?

If you’re unsure how REST Response works, this section is for you! Firstly, the client sends the requests, which directly go to the request handler. Then, the request handler interfaces with the REST module, where requests are sent forward to deserialze to normalize the data.

In the next step, deserialized data is sent to the request handler that matches up the resource with the appropriate resource handler. Once done, the request is sent to the Resource plugin, which receives an incoming request to gather data and retrieve valid information from the database. In the following step, the resource plugin returns the data to the request handler and again acts with the serializer before sending a response.

Also Read: Drupal 9 Vs. Drupal 8: Should You Upgrade Your Website To Drupal 9?

How can you configure the REST API in Drupal 9 using Core Modules?

Here are four simple steps to configure REST API by using core modules in Drupal 9: 

Step 1: Initially, install the core modules, including HTTP Basic Authentication, HAI, serialization module, and REST Web Services. 

Step 2: Then, download the REST UI module and enable it.

 

REST UI module

Also Read: Drupal 9 Plugins You Must Have For Your Website

Step 3: The following step is to configure the REST API endpoints. You can do it by going to Configuration -> REST -> Click on the edit button under the OPERATIONS section.

REST API endpoints
Also Read: Drupal 7 To Drupal 9 Migration: Estimated Time And Cost

Step 4: Clicking on the Edit button will open the edit window. Make changes as required, and then click on Save Configuration to save the changes.

Configuration


Got a Drupal project in mind? We at Alberta TechWorks can help you. Get in touch with us today!