Expose Drupal Content with JSON:API: Setup, Access Checks, and Limits
Enable Drupal core JSON:API to expose content entities as REST resources, then verify permissions and query performance before going headless.
29 Dec 2025, 13:38 UTC

Problem: your frontend needs Drupal content, but custom endpoints take too long
A product team wants to build a React or Next.js frontend that reads articles, taxonomy terms, and user profiles from Drupal. Writing a custom REST controller for every content type is repetitive, and maintaining custom serialization logic slows down the project. Drupal core includes JSON:API, a standardized module that exposes content entities as REST resources without custom code.
Thesis: enable JSON:API, then verify permissions and query behavior
JSON:API is a core module in Drupal 8, 9, 10, and 11. It implements the JSON:API specification for CRUD operations on content entities. The practical decision is not whether to use it, but how to expose it safely: which content types, which authentication method, and whether deep relationship includes will hurt database performance.
What JSON:API exposes out of the box
Once enabled, JSON:API automatically exposes node, taxonomy, user, and custom entity types. Each bundle gets its own endpoint, such as /jsonapi/node/article or /jsonapi/taxonomy_term/tag. Standard query parameters support filtering, sorting, pagination, and sparse fieldsets:
- ?filter[title]=Drupal filters results by a property.
- ?sort=-created sorts by creation date in descending order.
- ?page[limit]=5 limits the page size.
- fields[node--article]=title,body returns only the requested fields.
Responses respect Drupal entity access checks and cache tags, so users only see content they have permission to view.
Worked example: enable the module and query an article resource
- Where to run: in the Drupal root directory, or through the Extend page in the administrative UI.
- Required permissions: administrator role or the "Administer modules" permission.
- Command: drush en jsonapi -y
- Rollback: drush pm:uninstall jsonapi -y disables the endpoint. Content is not deleted, but any frontend relying on the resource will break until the module is re-enabled.
- Request:
curl -i -H "Accept: application/vnd.api+json" \ "https:///jsonapi/node/article?filter[title]=Drupal&page[limit]=5" - Expected checks: HTTP 200, a top-level data array, and links.self plus links.next when additional pages exist.
- Risk: if anonymous users have "View published content," published articles are visible through the endpoint. Review permissions at /admin/people/permissions before exposing content types that contain drafts, private fields, or sensitive data.
Authentication, relationships, and included resources
Authentication integrates with Drupal cookie, basic, and OAuth2 systems. For a decoupled frontend, cookie authentication works when the frontend shares the domain; OAuth2 is better for mobile or third-party clients.
Relationships let clients fetch related entities in a single request. For example:
/jsonapi/node/article?include=field_tags,author
returns articles together with their tags and authors in the included section. This reduces round trips, but deeply nested includes can cause N+1 query patterns and slow down the site.
Limitations and a practical verification step
- JSON:API is optimized for entity CRUD, not complex business logic. Custom business operations may still require custom REST controllers or JSON:API resource customizers.
- Contributed modules do not always expose JSON:API resources automatically; custom entities may need explicit setup.
- Entity access depends on Drupal permissions and view modes. Misconfiguration can over-expose data.
Practical check: request /jsonapi/node/article on a staging copy and confirm the response contains data, links, and working filter, sort, and page parameters. Monitor database query counts when testing include with multiple relationship levels.
Closing: start on staging, then decide
Enable JSON:API on a non-production environment first. Query one content type with filters and includes, review role permissions, and watch query performance. If the frontend only needs standard content reads, JSON:API is usually sufficient. If it needs custom actions or heavy aggregation, plan for custom endpoints alongside it.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.