Topic
Last updated October 25, 2018

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 8, 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

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.

More Guides

We have guides on many Drupal skills and topics.

Explore 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.