Skip to content

Support Last-Modified or ETag headers on critical REST API endpoints #3329

Closed
@ghys

Description

@ghys

Idea from openhab/openhab-webui#1650 (comment):

The Main UI (and possibly others) makes relatively frequent REST API calls to get all things, or item, or rules, or UI components to make sure the data is up-to-date. For instance every time an item or thing picker is rendered, a call to /rest/items resp. /rest/things is performed.
/rest/items is also called every time the home page is shown, to compute the model cards (locations, equipment, points) with the latest data.

It could be a huge performance improvement if these critical and costly endpoints supported either the ETag or Last-Modified HTTP response headers, and their equivalent request headers (If-None-Match and If-Modified-Since).
If the preconditions don't match (see JAX-RS - Handling 'Last-Modified' and 'ETag' headers with Request Injection) then a 304 Not Modified response would be sent instead.

The UI and other clients would store the last known list of entities in a client-side cache (possibly even surviving page refreshes with IndexedDB), as well as the last sent EntityTag or modified date retrieved from the response headers, which would then be sent along with future requests. It would react to a 200 OK response by updating the cache before returning the data to the caller, and to a 304 Not Modified response by simply returning the cache.

To determine if the data has changed, resources backed by a Registry could keep the last sent EntityTag or last modified date as well, and add a change listener to reset this last ETag or date when a change was notified.

For items it would surely be a little more complicated since changes to metadata would have to be handled as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementAn enhancement or new feature of the Core

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions