How to configure views REST export in Drupal 8

Parent Feed: 
  • By : Prince
  • Date :10-04-2018

As all know, Drupal 8 is API driven first and keeps on adding in new API's which can be altered, extended for different decoupled Applications. When we talk about decoupled Drupal, developers are allowed to use any technology frontend to bring in better User experiences. The actual UI experience is met when we present contents which fulfill the needs and requirements of the user.

Drupal 8 Views

Drupal 8 views are now in the core and are among the greatest features available with Drupal to handle any type of dynamic UI designs to bring in better user experiences. Using RESTful views, we can embed views content to external applications.

In this guide, you will learn how to get the view content in JSON or XML format via Rest API.

  • Step1.¬†Go to admin/modules and enable the required modules available in the core (REST and Serialization).
  • Step2. Next, For testing purposes, you can create dummy content using the existing content types. (Articles or Basic page)
  • Step3. Now, create a view using the available content. We don't need to select a page or block while creating views.
  • Step4. After you have created a view with the required fields, we need to select REST export display from the Add options right of Master display in the views.

Drupal 8 Views

  • Step5. Specify a path for REST export which will be used to return formatted contents of the created view display.
  • Step6. You will also find an option to select the required format (say JSON, XML etc.) that will be allowed in the responses.

That's it, you have the Request URL to return either entities or fields from views. When you try accessing the URL directly on the browser, you will have view exported with the format you have selected or JSON by default. Also, you can test the formatted data using POSTMAN services available with Google Chrome.

Hope, the above steps will help you built REST API using Drupal views. Get in touch with our Drupal developers if you face any queries working with API's. We will be glad to help.

Subscribe For Our Newsletter And Stay Updated

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