The Consumers module for great decoupled Drupal 8 performance

Dec 07, 2017
The Consumers module for great decoupled Drupal 8 performance

We have heard so many times the phrase “You should know your consumer.” However, it’s mostly used by marketers. Here is another use for the same idea — why and how Drupal backends get better “acquainted” with their consumer frontend applications. As you might have guessed, we are talking about the overwhelmingly popular headless, or decoupled Drupal approach, where Drupal plays the backend role and outputs its data to some other front-end, which is a consumer in this case. Today, we’ll tell you about improving the communication between the front-end and back-end due to the newly created Drupal 8 module called the Consumers.

Headless and almost spotless: a little drawback of headless Drupal

The advantages of decoupled Drupal are numerous. It lets you supercharge your site with unprecedented dynamic features and ultra-high speed thanks to adding JavaScript front-ends. It addition, you are fully free in outputting our website’s data to mobile apps or any other apps you like. In Drupal 8, this has become much more advanced thanks to built-in web services for better third-party integration. And it’s just the top of this tasty cake.

However, the separation between the frontend and backend sometimes gets in the way. Imagine, for example, a headless Drupal website just exposes a public API without even knowing which apps consume its data, how they will display it, and what their settings are. Compared to the monolithic architecture, this approach may cause some inconsistencies in data presentation.

The Consumers module to fix headless Drupal’s drawback

For every drawback, there is a solution in Drupal. Here is where the special Consumers module for Drupal 8 comes in. It lets the Drupal back-end know the information about the consuming apps by creating an entity type called Consumer.

With the help of this module, all your website’s modules can discover what they need to know by adding the appropriate fields to the entity type.

It’s up to the consumer developers to provide the configuration they need so your backend interacts with them in the best way possible. Your site can build variations of functionality depending on the consumer making the request.

Slightly more than three months have passed since the module’s stable version appeared, and it already has almost 20,000 downloads, which is an impressive figure.

The Consumer Image Styles module

As an example of modules using the Consumer module, it’s worth distinguishing the Consumer Image Styles module. It lets third-party apps specify the image styles they need. The URLs for the appropriate image variations are added in cooperation with the JSON API.

Final thoughts

It’s time to take the best from headless Drupal scenarios using the Consumer module or creating custom solutions. Drudesk developers are ready to help you with the setup in accordance to all your wishes. Drupal can be headless and spotless at the same time. Just contact our team!

 Get new blog posts by email