Site Building
Topic

Web Services and Decoupled Drupal for Drupal 7, 8, 9, and 10

According to the W3C, a web service is a software system designed to support interoperable machine-to-machine interaction over a network. In other words, a web service is any software that allows two or more programs (machine-to-machine) to exchange information and/or instructions (interoperable interaction) across the Internet or a local area network.

When it comes to web services and Drupal there are two distinct things you can do: configure Drupal to expose data and actions as a service that can be consumed via a third party, or use Drupal to consume content from, or interact with, a service provided by a third party.

Pro tip: The Drupal community often uses the term headless, headless Drupal, or Decoupled Drupal to describe the process of using Drupal as a web services API provider. So keep an eye out for tutorials and documentation that mention headless or decoupled Drupal.

Example tasks

  • Expose data in a Drupal site as JSON via a REST API
  • Allow users to authenticate against Drupal from different clients
  • Write a module that interacts with an API provided by a third party

Confidence

The web services landscape in Drupal, especially with regards to implementing an API, is constantly evolving. Much of this work is happening in contributed modules and may or may not make it into future versions of Drupal core. For this reason we recommend looking for up-to-date and more recent content where available.

Drupalize.Me resources

Categories
Drupal 8, 9, and 10
More information

One of the ways you can create a REST endpoint in Drupal is by using Views. In this tutorial, we'll add a REST endpoint display to a view of baseball players. We'll examine and configure settings that are unique to the REST endpoint display.

By the end of this tutorial you should be able to:

  • Add a REST endpoint display to a view
  • Understand how to configure settings for an endpoint
Posted on Wednesday, December 9, 2015 - 08:02 by William Hetherington

With the release of Drupal 8 comes a new way of making web requests, available via the Drupal::httpClient. This is simply a wrapper for the wonderful Guzzle HTTP Client. In this post, we'll take a look at how we can use the Drupal::httpClient class for making HTTP requests in a module.

Entities

Topic
Drupal 7, 8, 9, and 10
More information

Entities are the fundamental building blocks that make up any Drupal site. Having a good understanding of the Entity system is an important part of ensuring the data model of your Drupal site is set up properly.

Guides

Not sure where to start? Our guides provide useful learning tracks for all skill levels.

Navigate guides

External resources

  • REST and Application Integration (api.drupal.org)
    • Official Drupal core documentation on implementing and consuming web services. This is useful to learn how the system works, but at the moment we generally recommend using contributed modules like JSON API or RESTful that provide more full-featured implementations. These will likely be incorporated into future versions of Drupal core in some way or another.
  • DrupalCon Baltimore 2017: Advanced Web Services with JSON API (youtube.com)
    • This presentation looks at best practices for implementing a web services API in Drupal, as well as some common gotchas, and useful contributed modules.
  • Contenta CMS (contentacms.org)
    • Contenta is a Drupal distribution that bundles many best practice contributed modules and configuration. This is a great way to quickly create a Drupal-based web services API, or to learn about how others are doing it.
  • Serialization API overview (Drupal.org)
    • Drupal uses the Serialization API to convert content and configuration entities into various formats like JSON and XML.
  • Authentication API overview (Drupal.org)
    • Documentation that covers how HTTP requests are authenticated in Drupal. Also contains links to modules providing common authentication methods like OAuth.
  • React for Drupal
    • A page that lists up-to-date resources for using Drupal with ReactJS.