Drupal 8

Web Services with Views: Drupal 8

Web-Services is one of the Awesome concepts on the web right now

A few days earlier, I was thinking let’s shift my photography website (www.sachlife.com) Drupal 8 and I have started building my website on my local server.

Drupal 8 is mobile responsive and that is something I am looking for my audience as they check my blogs/articles frequently on any device. After investing my after work hours into development I realized, “I should have developed Mobile App too ūüėõ (I don’t¬†know when I will get time for that) “.

Since Drupal 8, provides out of box web service support, I can utilize that.

Let’s explore more about Web-Services with Drupal 8.

What is REST?

REST is the principal way to access & manipulate data in Drupal 8 via using HTTP.

Drupal 8 core uses two significant module for working REST API first approach.

  1. Serialization РSerialization is not doing any REST API activities. This module is for converting entity into serialization JSON or serialization into XML or any specific format we specified in the configuration.
    Entities can be anything, content from content types, Taxonomy, etc.
  2. RESTful Web Services РOnce we serialized our data, we need to expose this to outside world with help of RESTfull Web Services module.

This is basic information about REST API with Drupal 8. Let’s see how we can use that in little bit interactive way.

Step 1: Go to your Extent page from Admin dashboard and enable WEB SERVICES modules.
HAL, HTTP Basic Authentication, RESTful Web Services, Serialization

REST UI module is not shipped with Drupal 8 core. Download it from Drupal.org (this module is optional)



Step 2: Configuration

Click on Configuration tab from Admin dashboard and go to WEB SERVICES section

Click on REST for REST server settings configuration

Step 3: By Default Content Resource is enabled.

We can enable more resources from Disable list.


Step 4: Set up content resource configuration by clicking Edit button.

Configure methods by checking checkboxes for GET, POST, DELETE, PATCH

We can specify request format and also set Authentication providers.


Step 5: Create content and request data.

I am creating content with help of Content type ‘Article’, you can use any content type for content creation.

Enter Title, Body Description and other fields in the content creation form.

Click on Save for the content publishing process.

Step 6: We have successfully created content and now create views with use of REST Export Settings section.

Enter View name and description for our REST Example view.

Inside REST EXPORT SETTINGS section, click Provide a REST export checkbox and provide URL in the textbox.

After that click on Save and edit button.

Select Fields to configure fields in for REST View.

Select Body field.

We need Node id, Title, Description of the content type Article. After configuring all fields, our view setting page will look like this.

Click on Save button and save view setting.

Step 7: REST View is ready and now let’s dig into¬† Postman tool to check our REST APIs.

I am using Postman Chrome extension to check WEB APIs, you can use any tool for testing.

Enter URL in the URL textbox.

We are using GET method here to retrieve Article content, Select Get in the drop down.

Hit the send button.

We are getting Data in the JSON format for our REST API.


Hurray! This is the basic example of WEB API using Drupal 8.

Try this on your local machine. I will add more Blogs on this topic.

Stay tuned for advanced activities of WEB Services.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s