Module Development

JSON:API Filtering Collections for Drupal 8, 9, and 10

Collections are a very powerful feature because they allow us to access multiple items at the same time. However, in many situations we do not want to access all the entities of a given type, but only the ones that meet some specific criteria. In order to reduce the set of entities in the collection to the ones we care about, we use filters.

In this tutorial we will:

  • Look at the filter query string parameter and how it can be used with JSON:API collections
  • Learn how to use filters in combination with the JSON:API module for Drupal to reduce the list of entities in a collection

By the end of this tutorial you should be able to request a list of entities in the form of a JSON:API collection and filter that list to include only the entities that match a specific set of requirements.

Decoupled Headless Drupal