Importing (deploying) REST resource config entities should automatically do the necessary route rebuilding

Created on 10 October 2016, about 8 years ago
Updated 12 September 2023, over 1 year ago

Problem/Motivation

While working on #2737719: EntityResource: Provide comprehensive test coverage: for every entity type, every format, every method , I noticed it was unfortunately necessary to rebuild the router whenever you imported (i.e. deployed) RestResourceConfig config entities. This should happen automatically thanks to a ConfigEvents::SAVE event subscriber.

Worse, you actually even need to call drupal_flush_all_caches(): just calling $this->container->get('router.builder')->rebuild() is insufficient! (I have no idea why yet.)

When doing an import through the UI, this means you need to go to /admin/config/development/performance and click the button. If a developer forgets this step, then their REST routes won't work.

Proposed resolution

  1. Routing system:
    1. Add http_response cache tag to all cacheable responses.
    2. Let route rebuilder invalidate the http_response_ cache tag after every rebuild.
  2. REST module:
    1. Make RestResourceConfig::post(Save|Delete) mark the router as needing a rebuild.
    2. Implement a REST config save event subscriber (for the rest.settings config) that marks the router as needing a rebuild.

Together this means that:

  1. every router rebuild will now invalidate all responses. Cached 404 responses may become 200s, 200s may become 403s, 404s may become 403s, and so on. Hence all cached responses need to be rebuilt.
  2. whenever RestResourceConfig config entities or rest.settings simple config change, mark the router as needing a rebuild, which will trigger the above.

Remaining tasks

None.

User interface changes

None.

API changes

None.

Data model changes

None.

📌 Task
Status

Fixed

Version

8.4 ⚰️

Component
REST 

Last updated about 1 month ago

Created by

🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024