Drupal JSON:API 2.x module

Drupal JSON:API 2.x module: new release to build high-performance APIs

Drupal 8 is known for the extensive third-party integration opportunities it gives to websites. One of the tools for this is the contributed Drupal module JSON:API. It helps developers build high-performance APIs for various purposes, including multi-channel content or decoupled Drupal and JSON API setups (which is one of our Drupal team’s areas of expertise). This winter has seen a new release — Drupal JSON:API 2.x. Let’s take a look at what the module does, what makes it useful, and how it has changed in the 2.x version.

JSON:API: principle and benefits

JSON API is a specification, or a set of rules, for REST APIs. It defines how data is exchanged between the server and the client in the JSON format. This includes how the client requests the resources, how they are fetched, which HTTP methods are used, and so on.

JSON (JavaScript Object Notation), in its turn, is the most popular format for APIs. It is very lightweight, consistent in structure, intuitively understandable, human-readable, and easily consumable by machines. At the root of all the requests is a JavaScript object.

The JSON API specification optimizes the HTTP requests and gives you better performance and productivity. JSON API eliminates unnecessary server requests and reduces the size of the data packages.

The specification supports the standard CRUD operations that let users create, read, update, or delete the resources. It is also accepted by all programming languages and frameworks.

crud operations

A glimpse at Drupal JSON:API module’s work

The Drupal JSON:API module offers Drupal’s implementation of the JSON API specification. The module provides an API in compliance with the JSON:API standards for accessing the content and configuration entities of Drupal websites.

The JSON:API module is part of Drupal 8’s ecosystem of web services, and also an alternative to Drupal’s core REST. JSON:API resolves some of the core REST limitations (for example, complex setup, confusing URLs, hard-to-configure collections of entities etc.). At the same time, it only works with entities.

Let’s note some important points about the benefits of the JSON:API work:

  • no configuration is needed (enabling the module is enough to get a full REST API)
  • instant access to all Drupal entities
  • URLs provided dynamically for entity types and bundles so they are accessible via standard HTTP methods (GET, POST, PATCH, DELETE etc.)
  • support for Drupal entity relationships
  • support for complex sorting and pagination
  • access configured in Drupal core role and permission system

As we see, the main philosophy of the module is to be production-ready out of the box. For configurations, there is a related contributed module JSON:API Extras module that lets developers set up every detail they need.

Drupal JSON:API 2.x: what’s new?

Drupal JSON:API 2.x module is getting ready to become part of Drupal 8 core in the near future. Thanks to this, the ecosystem of web services to build high-performance APIs in Drupal 8 core will soon be more complete and diverse. It is also great that Drupal will have a NIH (not invented here) API in its core that follows a very popular specification.

The creators of the JSON API module have had a busy time preparing the 2.x module version for Drupal 8 websites. Overall, 63 contributors took part in that. And there is still a big roadmap ahead.

They issued two beta versions in August and September, then three release candidates from October to December of 2018.

Finally, the stable 2.x version came — JSON:API 2.0 in January 7, 2019, bringing big changes. Websites will benefit from:

  • serious performance improvements (including sparse fieldsets)
  • better compatibility with JSON:API clients
  • more comprehensive test case coverage (including edge cases)
  • backwards compatibility with JSON:API 1.x
Drupal JSON API 2.x improvements

 

As well as:

  • the ability to see labels of the inaccessible entities
  • information about the user available via “meta.links.me”
  • error response cacheability
  • the config entity mutation feature moved to the JSON:API Extras module
  • a final farewell to the _format parameter in the URL
  • custom "URL" field to no longer added to file entities
  • filter paths closely match JSON:API output structure
  • URLs become objects with `href` keys

and more.

Drupal JSON:API 2.0 was soon followed by a new one — JSON:API 8.x-2.1 in January 21, 2019. This is now the latest stable version. Drupal JSON:API 2.1 added two new features:

  1. support for file entity creation from binary data
  2. support for fetching non-default entity revisions.

We should also note that Drupal JSON:API 2.x module is part of the Contenta CMS decoupled distribution that uses best practices of decoupled architecture. JSON:API is immediately available with all new installs of the Contenta.

The related module JSON API Extras for customizing APIs is also fresh and updated. It has had a new 8.x-3.3 release on January 21.

Let’s build the optimal JSON:API setup

As we see, there are plenty of means and tools to build high-performance APIs. Our Drupal developers are keen in this area, and will select the optimal ones for your website. It can be the Drupal JSON:API 2.x module, core RESTful web services, GraphQL, and more. Contact our Drupal team!

Follow WishDesk

Join our Newsletter

Check out our Privacy Policy for more information.

Join our newsletter to get blog updates straight to your inbox.

Follow WishDesk

Join our Newsletter

Check out our Privacy Policy for more information.