Module Development

JSON:API Relationships for Drupal 8, 9, and 10

Drupal allows for a rich data model where entity reference fields can be used to relate any number of different items together in different ways. The data models that you can build with Drupal are often prolific in relationships, which means we need a way to handle these in our API. While Drupal treats a field with a string, and a field with an entity reference the same, JSON:API distinguishes between attributes and relationships.

In this tutorial we'll:

  • Look at how JSON:API represents relationships between two or more resources
  • How to distinguish between an attribute and a relationship in a response object
  • Learn about what information is available for each relationship and how we can use it

By the end of this tutorial, you should have a better understanding of how the JSON:API specification represents relationships modeled using Drupal entity reference fields.

Decoupled Headless Drupal