Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough

Drupal 8 Initiative - Web Services

In this post, I''ll be discussing Drupal 8 Initiative Web Services and Context Core.

Drupal is open source software maintained and developed by a community of hundreds of thousands of users and developers. It is distributed under the terms of the GNU General Public License (or “GPL”), which means anyone is free to download it and share it with others. It is an open-source CMS or Content Management System. Drupal 8 is the latest version of Drupal Family and with it, 5 initiatives were initiated. These initiatives started as an idea and when no one could even think of these as possibilities, Drupal took the decision to initiate their plans. The 5 initiatives were:

  1. Configuration Management

  2. Web Services and Context Core

  3. Multilingual

  4. HTML5

  5. Mobile

Introduction to Drupal-8 Initiative "Web Services"

This is Drupal 8''s second Core Initiative. So, basically Web Service is a website responding to a request not with an HTML page but with data intended for another program to consume. Before this initiative Drupal wasn''t able to serve content as JSON(JavaScript Object Notation) or XML(Extensible Markup Language) and it only provided the HTML content.

Before this initiative, Drupal used its "Services" module and was only supporting Web Services. After this initiative, they will themselves become a Web Service with a CMS. That won''t only save time or make it easy for the developer by making him do a little less work, but it will also enhance the performance of the website.

The Web Services and Context Core Initiative (WSCCI) aims to transform Drupal from a first-class CMS to a first-class REST server with a first-class CMS on top of it.

But, lets understand what is a REST server first. The basic idea of REST is to make some "objects" available via URIs in the web. So, for example if a user/1 points to a user, a client code can be used to retrieve that user and then Drupal will be able to serve the user with XML, JSON or HTML.

Importance

Web Services are exploding in today''s internet world and are surely going to get more importance in the future. Drupal had to keep up with the present and that isn''t only going to benefit Drupal itself, but will also benefit the users.

Before this Drupal wasn''t able to fulfill several requirements when it came to receiving content from URIs. Modules are Widgets were required to do so. Now, that it won''t be supporting these Web Services anymore and will be becoming one is going to make things easy for the whole Drupal Community.

Drupal is a great platform and this is the perfect step forward in making it even better.


 

This initiative is a great step towards changing Drupal into a Web Service itself. Web Services is included in core initiative and features of Drupal 8. Making Drupal 8 a web service itself won''t only save time and effort, but it also enhances the speed of the website. It enhances the user-experience and makes it easy for the developer to setup the services.

Setting up the Web Services on Drupal.

So, Drupal 8 started shipping with these four modules which were related to Web Services. Also an important module is Rest UI module to set up the web services. This module is supposed to be added in the modules folder.

 Once, the module is enabled, you can go to Admin->Configuration->Services->Rest to take a look at the list of resources. It would be something like this.


 

Now, you can see a list of entities and know how to interact with these. You can also edit the authentication and formats here. For now, you don''t have to change the authentications and don''t have to restrict them. But, in permissions section change "Access GET on Content Resource" to anonymous users.

Interact with the REST server

Use any HTTP advisor client to interact with the REST server. For illustration purpose we are using Postman for Chrome. Insert the URL http://localhost/blog/node/1?_format=json (Blog is the directory where drupal is installed in this case)

If everything goes well, you''ll receive a node object with all the fields in JSON and you''ll have something like this on screen.


 

Now, lets learn how to use views. Drupal 8 installed Views in its core too unlike the previous versions of Drupal. In the following steps, I''ll teach you how to list nodes from a certain content type and expose them via webservices.

Firstly create a new view.


 


 

Define a new display as REST export, define a path, save it and check the defined output again with the Chrome extension we installed before.


 


 

In the above screenshot, I defined the path as /articles_rest. So, if you do the same, just open up http:yourwebsite.com/articles_rest. The result will expose views as REST Resource and it will look something like this.


 

You''re done with the basics now, but you can extend REST module by adding plugins.

How can you help?

You can contribute your ideas for the betterment and progression of this initiative. The IRC channel can be used to discuss the matters and issues. You can even interact with the developers on IRC to learn more about this initiative.

https://www.drupal.org/irc

Author: 
Original Post: 

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web