Problem/Motivation

Backwards compatibility policy for Drupal APIs is clear, and can often be used to infer the compatibility policies that might cover the Drupal REST implementation. However, without REST design documentation and an explicit policy, it is difficult for anyone thinking about providing a Drupal-based Web API or consuming a "vanilla" Drupal REST API to know what kinds of things might break on upgrades. This makes the risk of operating or integrating with Drupal REST a large and unknown quantity.

Such a document would also help jump-start best practices for individual REST-enabled Drupal systems, whose documentation/communications resources should reference or start with this text.

Proposed resolution

Document REST backwards compatibility policies to help steer development, and reference this from places in the Drupal codebase, API site, and others so technologists looking for this information can find it easily. Similar to the D8 "internal" B/C policy, the kinds of changes allowed should be tied to versioning. In this course of deriving this policy we may find a follow-up to separately track REST version from Drupal application version, a generally recommended practice that allows APIs and Application to evolve unencumbered from each other.

Items to Cover

Top-of-mind list.

  • HTTP Headers (discussion of common headers like CORS and Caching helpful)
    • Removal of Headers
    • Addition of Headers
    • Change in Header values
  • Entity Properties
    • Removal of entity field
    • Name change of entity field
    • Addition of entity field
    • Change in structure of entity field
    • Change in field item value format
    • Change in field item value
  • Resource path

Remaining tasks

  • Decide on some initial policy points
  • Draft documentation
  • Find a home
  • Identify reference locations

User interface changes

Possibly if there are spots in the Admin determined to reference the new documentation.

API changes

None

Data model changes

None

Comments

Grayside created an issue. See original summary.

Grayside’s picture

Title: Decide & document a backwards-compatibility policy for REST API » Decide & document a backwards-compatibility policy for REST resources

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

alexpott’s picture

Added some related issues that have discussion BC changes or REST APIs

Wim Leers’s picture

Title: Decide & document a backwards-compatibility policy for REST resources » API versioning: decide & document a backwards-compatibility policy for REST resources
Priority: Normal » Major
Issue tags: -REST

Clarifying issue title.

klausi’s picture

Yes, this is hard. We should only break API consumers when absolutely necessary, but we also should not restrict ourselves to deliver the exact bit by bit REST responses forever.

Some suggestions:
HTTP headers: This is metadata. Values should be covered by the HTTP spec. We should not give any guarantees here - all response headers are subject to change and clients should not rely on headers always being present. We should document specific exceptions. Example: after creating a node with a POST request there will always be a Link header in the response with a link to the created node.

Entity fields:
Base fields must never be removed. This is consistent with the core API where we promise to never change NodeInterface for example.
Base fields can be added: I think clients should be robust enough to work with responses that suddenly have more base fields. We should produce a change notice though.
Change in field structure/format/value: I don't know. Decide on a case by case basis? #2751325: All serialized values are strings, should be integers/booleans when appropriate for example took a good sensible approach by assuming that most clients will just be fine.

Resource paths: should be stable and not change. We can allow new paths though and still support old ones. Example: POST /entity/node keeps working, but we can also receive requests at POST /node.

Serializer data formats: should be stable, we won't make arbitrary changes like changing a [] structure to {} in JSON.

In general all minor REST API changes should be documented in change notices, but I think we are doing that already.

alexpott’s picture

This is consistent with the core API where we promise to never change NodeInterface for example.

In fact additions are allowed.

Wim Leers’s picture

#7: But… then existing implementations would break because they don't implement a new interface method? Only optional additions are allowed:

  • a new interface extending NodeInterface that adds an additional method
  • adding an optional parameter to an existing method.

EDIT: this principle applied to REST means that it's disallowed to add required fields to entity types.

Wim Leers’s picture

Category: Task » Plan

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

gabesullice’s picture

I very much agree with #6 WRT HTTP headers and base fields (accepting the caveat in #8).

I wonder if REST shouldn't draft a specification similar to the JSON API specification. The conventions like MUST, SHOULD
and MAY are incredibly useful. It would allow REST to leave areas undecided and permit flexibility in areas not yet fully explored (e.g. revisioning/translations). A spec also provides useful guidance to client implementations on what inconsistencies they should expect (and program against).

Something that hasn't brought up, is that clients are not necessarily tied 1:1 with the Drupal backend. In fact, one of the promises of decoupled Drupal is that one can implement different frontends over time w/o necessarily changing the backend. Therefore, I'd like to toss the idea out that our HTTP API versions can be more like hook_update_N numbers, rather than 1:1 mappings to the core version. It would be ideal if we could support different versions of the API concurrently. This article lays out an approach that we may be able to adapt to our needs: https://stripe.com/blog/api-versioning

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.