Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Views Better REST export

Security covered Maintenance fixes only 160 sites

Part of the Views ecosystem · 291 projects

Views Better REST is a Drupal module that enhances the REST export display for views, enabling more flexible JSON output. It allows custom JSON structures, supports exposed filters, pagers, and sorts, and adds URL serializer support.

πŸ‡ΊπŸ‡¦

This module is maintained by Ukrainian developers.
Please consider supporting Ukraine in a fight for their freedom and safety of Europe.

Views Better REST export adds a Better REST export display to Views. Like the core REST export, it returns the results of a view as JSON, and it also describes the pager, the exposed filters and the exposed sorts with their options. A decoupled front end, a mobile app, an autocomplete or a faceted search can build its listing, filters and paging from a single request.

Features

  • Exposed filters
  • Exposed sorts
  • Pager
  • Facets (Search API)
  • JSON and XML
  • Field aliases
  • Raw output
  • Field value types: numbers and booleans detected from the field types, other fields can be converted to a number, a boolean or JSON
  • Nested objects, e.g. a custom text field {"id": {{ uid }}, "name": "{{ name }}"} with the JSON value type becomes {"id": 7, "name": "Jane"} (for trusted output only)

Usage

Set it up like a core REST export display:

  1. Add a Better REST export display to a view, set its path, e.g. api/v1/articles, and select the Better REST serializer format and Fields.
  2. Add fields, and set their Alias and Raw output in the Fields settings.
  3. Add exposed filters, exposed sorts and a pager, and for Search API views, facets with the Array widget and Show Facets enabled in the format settings.
  4. Request the path with the usual Views query parameters.

An example view, Content REST (/api/node), is installed disabled.

Example

GET /api/v1/articles?type=article&sort_by=created&page=1


Response

{
  "endpoint": {
    "path": "api/v1/articles",
    "args": [],
    "requested": "/api/v1/articles"
  },
  "pager": {
    "active": true,
    "current_page": 1,
    "total_items": 42,
    "items_per_page": 10,
    "total_pages": 5
  },
  "exposed_filters": [
    {
      "identifier": "type",
      "label": "Content type",
      "options": {"article": "Article", "page": "Basic page"},
      "submitted_values": "article"
    }
  ],
  "exposed_sorts": [
    {"label": "Authored on", "field_identifier": "created"}
  ],
  "rows": [
    {
      "id": 31,
      "title": "Decoupled listings with Views",
      "promoted": true,
      "author": {"id": 7, "name": "Jane"}
    }
  ]
}

(Shortened: the pager settings and the filter details are left out.)

Recommended modules/libraries

Works well with React Table for rendering the listings, with Search API and Facets for faceted search, and with Simple OAuth or the core Basic Auth module for clients on other sites.

Upgrading to 1.4

Numbers and booleans are now detected from the field types, and other fields are only converted when configured. The update enables JSON for all fields of existing Better REST export displays, so their output does not change, except raw boolean values, which are now true and false instead of 1 and 0. Review the Field value types of these displays afterwards, and keep fields with user input as strings.

Similar projects

REST Views adds features to the core REST export, and can be used together with this module.

JSON:API Views exposes views through JSON:API, but its path and exposed parameters can not be configured.

Drupal 10–11

Ask your assistant about Views Better REST export

Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works

Depends on

Dependencies of the latest stable release

  • rest Drupal core
  • views Drupal core

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
7
Tracked since
Aug 2023
Latest release
5 days ago
Releases (12 mo)
2
Maintenance
Active

Release Timeline

Releases

Version Type Core PHP Release date
1.4.0 Stable 10–11 Nov 24, 2026
1.3.0 Stable 10–11 Nov 12, 2026
1.2.0 Stable 9–11 Mar 8, 2025
1.x-dev Dev 9–11 Mar 8, 2025
1.1.x-dev Dev 9–11 Oct 7, 2024
1.0.0 Stable 9–10 Sep 18, 2023
1.0.x-dev Dev 9–11 Aug 12, 2023