Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Drupal 10 Development Cookbook - Third Edition

You're reading from  Drupal 10 Development Cookbook - Third Edition

Product type Book
Published in Feb 2023
Publisher Packt
ISBN-13 9781803234960
Pages 442 pages
Edition 3rd Edition
Languages
Concepts
Authors (2):
Matt Glaman Matt Glaman
Profile icon Matt Glaman
Kevin Quillen Kevin Quillen
Profile icon Kevin Quillen
View More author details

Table of Contents (17) Chapters

Preface 1. Chapter 1: Up and Running with Drupal 2. Chapter 2: Content Building Experience 3. Chapter 3: Displaying Content through Views 4. Chapter 4: Extending Drupal with Custom Code 5. Chapter 5: Creating Custom Pages 6. Chapter 6: Accessing and Working with Entities 7. Chapter 7: Creating Forms with the Form API 8. Chapter 8: Plug and Play with Plugins 9. Chapter 9: Creating Custom Entity Types 10. Chapter 10: Theming and Frontend Development 11. Chapter 11: Multilingual and Internationalization 12. Chapter 12: Building APIs with Drupal 13. Chapter 13: Writing Automated Tests in Drupal 14. Chapter 14: Migrating External Data into Drupal 15. Index 16. Other Books You May Enjoy

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…

  1. Navigate to Structure and then Views.
  2. Click on Add new view.
  3. 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

Figure 12.24 – Setting the path for Views for a custom REST endpoint

  1. Save...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}