Using Views to provide custom data sources
The RESTful Web Services module provides Views plugins that allow you to expose data over Views for your RESTful API. This allows you to create a view that has a path and outputs data using a serializer plugin. You can use this to output entities in JSON or XML and it can be sent with appropriate headers.
In this recipe, we will create a view that outputs the users of the Drupal site, providing their username, email, and picture if provided.
Getting ready
Make sure you have the following core modules enabled:
- Views
- Views UI
- RESTful Web Services
How to do it…
- Navigate to Structure and then Views.
- Click on Add new view.
- Name the view
API Users
and have it show Users. At the bottom of the View creation page, check off Provide a REST export. Give it a path of/api/users
:
Figure 12.24 – Setting the path for Views for a custom REST endpoint
- Save...