There are several modules provided by Drupal 8 that enable the ability to turn it into a web service provider. The Serialization module provides a means of serializing data to or deserializing from formats such as JSON and XML. The RESTful web services module then exposes entities and other APIs through Web APIs. Operations done through RESTful resource endpoints use the same create, edit, delete, and view permissions that would be used in a non-API format.
The HAL module serializes entities using the Hypertext Application Language (HAL) format. HAL is an Internet Draft standard convention used to hyperlink between resources in an API. HAL+JSON is required when working with POST and PATCH methods. For authentication, the HTTP Basic Authentication module provides a simple authentication via HTTP headers.
There is a community-lead effort to implement the JSON API specification with Drupal, using the JSON API module, covered in the Using JSON API recipe of this chapter. Like HAL, it provides specifications not only on how data should be represented, but also on how it should be sorted and filtered via request parameters.
This chapter covers how to work with the RESTful Web Services module and the supporting modules around developing a RESTful API powered by Drupal 8. We will cover how to use the GET, POST, and PATCH HTTP methods to manipulate content on the website. Additionally, we will cover how to use views to provide custom content that lists endpoints. Finally, we will cover how to handle custom authentication for our API.
However, the API is open for contributed modules to add the PUT support for core resources or their own.