×

Drupal JSON API, Deep Dive - Part 1

Read Article
Pause
Resume
Stop
Drupal JSON API, Deep Dive - Part 1

JSON:API module is implemented based on JSON:API Specification. Means, a specification that says how client should request the resources to be fetched or modified, & also how server should respond to such requests. This JSON:API is designed to minimize the number of requests and also minimize the amount of data transmitted between clients & servers. And such efficiency is achieved without compromising readability, flexibility, or discoverability.

Once you enable the JSON:API module, REST API for every type in Drupal application is available. JSON:API inspects the entity types and bundles so that it can dynamically provide URLs by which to access each and every one of them using the standard HTTP methods, GET, POST, PATCH, and DELETE.

  • Access control of APIs will be with Drupal Core's permissions system.
  • No configuration page available. Means you can get up and running with an API-driven Drupal application with minimal effort.

Request/Response terminology

  • HTTP requests are made to JSON:API resources. These are different from resource objects.
  • The JSON object that the client receives is refered a document.
  • A document is always a JSON object and it has primary data under a data key.
  • The data under that key are called resource objects or resource identifier objects.
  • When you request that related data be embedded in the document, it becomes a compound document.
  • A compound document is one with an included key in the top-level object.
  • Resources that return many resource objects are called collection resources.
  • Resources that return one resource object are called individual resources.
  • Resources that return information about relationships between resource objects are called relationship resources.
  • In Drupal terms:
    • Resource Objects -> Entities
    • Resource Identifier Objects -> Entity reference field Items
    • Document -> Request/response JSON payload

Let's see core concepts & API Overview in the next part.

Comments

Scroll to Top
We Need Your Consent
By clicking “I Accept Cookies”, you agree to the storing of cookies on your device to enhance site navigation & analyze site usage.
I Accept Cookies