Reader small image

You're reading from  Drupal 10 Masterclass

Product typeBook
Published inDec 2023
PublisherPackt
ISBN-139781837633104
Edition1st Edition
Tools
Concepts
Right arrow
Author (1)
Adam Bergstein
Adam Bergstein
author image
Adam Bergstein

Adam Bergstein is a product engineering leader and an architect. He has been a long-time Drupal community member, a routine speaker at Drupal community events around the globe, and provided keynotes for several events. He has maintained and contributed to many Drupal projects, including Password Policy, Taxonomy Menu, and more. Adam is the lead of Simplytest, a free service, and a project that offers Drupal community members testing sandboxes. He has also worked for both agencies building Drupal applications and Drupal service providers building Drupal-related products. He has led the Drupal Community Governance Task Force and is serving a term as a community board member of the Drupal Association.
Read more about Adam Bergstein

Right arrow

Delivering Drupal
Content through APIs

Drupal’s structured content capabilities can be used beyond just rendering content in Drupal. Modern JavaScript frameworks, such as ReactJS and Vue.js, and more, often rely on third-party web services. Drupal is a natural fit for this use case and has features out of the box. This chapter extends what was already covered for structured content by configuring web service APIs through Drupal’s JSON:API and REST capabilities. This helps configure web service endpoints that follow standard conventions and manage access to those endpoints. The chapter finishes by using and testing web services that can be called from any third-party system.

In this chapter, we’re going to cover the following main topics:

  • Web services primer
  • Web service APIs in Drupal
  • Using web services

Web services primer

Web services is a general concept that is used to promote systems interoperability. Companies often adopt or purchase products. Some of those products may be the source of truth for certain data or perform specific business functions. However, the technical implementation of these products and systems is often very different. Some of the implementation details, such as those found in SaaS products, are even abstracted from those who procured the service. But products often do not run in isolation and the need for interoperability has become a critical requirement for many businesses.

Let’s take the simple example of a website. Many websites, such as those in Drupal, have means of engagement. This engagement may come through a web form on a website to inquire about services or products for that business. But businesses often have different departments. The marketing or sales departments may be the recipients of the engagement. While Drupal could easily...

Web service APIs in Drupal

Drupal, which commonly maintains structured content and has features other systems may need, can play an important role in both calling and providing web services.

Drupal commonly refers to its backend and frontend. Out of the box, it offers both. But Drupal’s frontend can be replaced, often through the use of Drupal’s backend APIs. This approach is known as decoupled or headless Drupal. The frontend is not assumed. It could be an app on a mobile phone, an Internet of Things device, or even another web application.

A lot of recent focus has has harnessed web service features in Drupal to pull content for modern JavaScript frontend applications. Frameworks such as ReactJS and Vue.js can interface with any third-party web service and create performant, innovative web frontends. Drupal’s technology stack, given that it spans systems, backend, and frontend, often drives specific types of experts, such as a backend or frontend engineer...

Using web services

Any system that is capable of making an HTTP request can use web services. Covering those topics would be outside of the scope of this book given many different languages, platforms, tools, and capabilities have some support for web services. This section outlines how to invoke endpoints in Drupal using the aforementioned features.

Basic JSON:API examples

A catalog of available JSON:API requests can be generated from /jsonapi. The following figure shows part of a sample response:

Figure 20.5 - JSON:API catalog response

Figure 20.5 - JSON:API catalog response

This response provides a machine-readable response with a series of links to get to the configured resources. Each of the links provides more detail based on the resource. For instance, clicking on the link for block--block provides a catalog of blocks (metadata and block placement), as shown in the following figure:

Figure 20.6 - JSON:API block catalog response

Figure 20.6 - JSON:API block catalog response

Getting to the structured...

Summary

Drupal offers native web service API features that are complementary to its structured content. APIs leveraging Drupal’s RESTful Web Services or JSON:API modules can be used for decoupled or headless applications that build custom frontends outside of Drupal or connect with the Internet of Things, mobile apps, and more. Drupal helps provide serialization, authorization tied to its permission system, and common data formats (JSON and XML). Various contributed modules help manage these APIs and provide fine-grained controls.

The next chapter covers the basics of Drupal’s migration system, which is the primary tool used to migrate content into a Drupal application.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Drupal 10 Masterclass
Published in: Dec 2023Publisher: PacktISBN-13: 9781837633104
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Author (1)

author image
Adam Bergstein

Adam Bergstein is a product engineering leader and an architect. He has been a long-time Drupal community member, a routine speaker at Drupal community events around the globe, and provided keynotes for several events. He has maintained and contributed to many Drupal projects, including Password Policy, Taxonomy Menu, and more. Adam is the lead of Simplytest, a free service, and a project that offers Drupal community members testing sandboxes. He has also worked for both agencies building Drupal applications and Drupal service providers building Drupal-related products. He has led the Drupal Community Governance Task Force and is serving a term as a community board member of the Drupal Association.
Read more about Adam Bergstein