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, such as JSON, HAL 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.
- Got o
Extend
from the administrative toolbar and install the following Web Services modules:Serialization
andRESTful Web Services
:
- Go to
Structure
and then toViews
. Click onAdd view
. Name the view API Users and make it showUsers
. - Check the
Provide a REST export
checkbox, and type in theapi/users
path. This is where requests will be made:
- Click on
Save and edit
. - Change the format of the row plugin from
Entity
toFields
instead so that we can control the specific output. - Ensure that...