Understanding Headless Drupal

By Venkateswara Rao Adapa 3 min read

Drupal is one of the world’s most popular and widely used CMS frameworks. Drupal’s back-end system is strong and can be used for managing any type of content, including text, geospatial, categories and media.

What Is Headless Drupal?

The term “Headless Drupal” refers to using Drupal as backend system and Rest server, so that content operations (e.g., create, read, update, delete) can be done from another language or tool. Drupal 8 comes with Rest Server included in its core. Drupal 7 uses a contributed module called Services or RestWS to achieve the same functionality.

In today’s world, the diversity of computing tools is wider than ever. People are using a combination of desktops, laptops, tablets and smartphones to explore content on whatever device they choose. Likewise, businesses are aggressively targeting smartphone users and seek to provide services and gain sales through mobile apps, offers and ads.

Thus, front-end frameworks were invented to provide a better user experience while viewing content on a wide variety of devices.

About REST (Representational State Transfer) API

RESTful API has gained more popularity than SOAP- or WSDL-based web services because of faster development and easier usage. RESTful web services are resource-based and can work with a variety of “resources” including users, articles and categories. Although there are no strict rules for RESTful API creation, there are some good principles to follow, including how to change resource states and transfer them over HTTP.

There are four basic HTTP methods available to Create, Read, Update and Delete resources on a server.

GET: Retrieves a resource from a server
POST: Creates a resource in a server
PUT: Updates a resource on a server
DELETE: Deletes a resource from a server

A good developer should always follow these principles correctly to maintain consistency. See the example below.

Poor Practice: GET /api/addArticle?name=Foo HTTP/1.1

This is not a good design because the above web method “addArticle” supports a state-changing operation over HTTP GET, and upon successful execution, a new article with name Foo will be added to the database. Web servers are designed to respond to HTTP GET requests by retrieving resources that match the path (or the query criteria) in the URI request and return them in a response—not add a record to a database. The GET method should be used when retrieving articles like: GET /api/getArticles HTTP/1.1.

Good Practice: POST /api/addArticle?name=Foo HTTP/1.1

This is a better practice for adding a new resource (article) to the database, instructing the client to use the correct method (POST) to send the request.

The response from the server can be XML or JSON.

Most people prefer JSON as the response type since it is lightweight and can be parsed easily by any client side language.

The Drupal Services module can expose the resource nodes, users and taxonomies in a RESTful way. In addition, with custom code, we can deliver a JSON response instead of HTML by setting “delivery callback”; as “drupal_json_output” in the hook_menu implementation.

How Front-End Frameworks Interacts with the REST Server

All front-end (MVC JavaScript) frameworks have capabilities to process http requests and Angular JS is one that comes bundled with many services. $http is one of the services to process HTTP requests. Another service called $resource enables you to interact with RESTful servers (back-end data stores) easily.

All front-end (MVC JavaScript) frameworks have capabilities to process http requests and Angular JS is one that comes bundled with many services. $http is one of the services to process HTTP requests. Another service called $resource enables you to interact with RESTful servers (back-end data stores) easily.

Using Headless Drupal, content-rich backend work can be done very quickly and data can be exposed through REST API. Front-end work can be done by using any of the desired front-end frameworks (e.g., Angular JS, Backbone and others). We can also use the same REST API for developing mobile applications.

Through this, we can build different kinds of applications, including single page applications (SPA), responsive apps and mobile apps, with a single Drupal back-end system.

Explore Additional Resources

Learn how you can select the best Digital Experience platform for your business.

Our Acquia Certified Drupal experts specialize in helping you create intelligently personalized customer experiences.

GET HELP FROM OUR EXPERTS

We have one of the largest and deepest multi-solutions digital consulting teams in the world. Our proprietary processes and years of Digital Experience expertise have earned us a 97% customer satisfaction rating with our clients ranging from Global Fortune 1000 to Mid-Market Enterprises, leading educational institutions, and Non-Profits.

Contact us today if your organization needs assistance with your next Drupal project.

About TA Digital

TA Digital is the only global boutique agency that delivers the “best of both worlds” to clients seeking to achieve organizational success through digital transformation. Unlike smaller, regional agencies that lack the ability to scale or large organizations that succumb to a quantity-over-quality approach, we offer resource diversity while also providing meticulous attention to the details that enable strategic success.

Over the past 20 years, TA Digital has positioned clients to achieve digital maturity by focusing on data, customer-centricity and exponential return on investment; by melding exceptional user experience and data-driven methodologies with artificial intelligence and machine learning, we enable digital transformations that intelligently build upon the strategies we set into motion. We are known as a global leader that assists marketing and technology executives in understanding the digital ecosystem while identifying cultural and operational gaps within their business – ultimately ushering organizations toward a more mature model and profitable digital landscape.

Recognized in 2013, 2014, 2015, and 2019 Inc. 5000 list as one of the most successful technology companies in the United States, TA Digital is pleased also to share high-level strategic partnerships with world class digital experience platform companies like Adobe, SAP and Salesforce and possess global partnerships with industry leaders such as Sitecore, Episerver, Elastic Path, BigCommerce, AWS, Azure and Coveo.

Venkateswara Rao Adapa

Written By

Venkateswara Rao Adapa