[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Page MenuHomePhabricator

Allow requesting conditionally only returning data if item changed in GET /entities/items/{item_id}
Closed, ResolvedPublic8 Estimated Story Points

Description

As an application developer I only want to load the updated data from Wikibase instance, so I can update it in my app only when data changes

See If-None-Match and If-Modified-Since parameters in the specification: https://gerrit.wikimedia.org/r/773447

BDD
As an API user
GIVEN there is a newer and different version of item data than revision ID N
WHEN I make a GET request to /entities/items/{item_id}
AND I provide N as the revision ID in If-None-Match header
THEN I receive 200 HTTP response from the API
AND response contains item data
AND response headers contain the item metadata as indicated in the specs

As an API user
GIVEN The most recent version of an item is N
WHEN I make a GET request to /entities/items/{item_id}
AND I provide N as the revision ID in If-None-Match header
THEN I receive 304 HTTP response from the API
AND response headers contain the ETag header which is the most recent revision's ID

(multiple ETags)
As an API user
GIVEN The most recent version of an item is N
WHEN I make a GET request to /entities/items/{item_id}
AND I provide M, K, N as the revision ID in If-None-Match header
THEN I receive 304 HTTP response from the API
AND response headers contain the ETag header which is the most recent revision's ID

(weak comparison)
As an API user
GIVEN The most recent version of an item is N
AND past revision M contains the same data as revision N
WHEN I make a GET request to /entities/items/{item_id}
AND I provide M as the revision ID in If-None-Match header
THEN I receive 304 HTTP response from the API
AND response headers contain the ETag header which is the most recent revision's ID

(edge case, * only makes sense in conditional PUT requests)
WHEN I make a GET request to /entities/items/{item_id}
AND I provide * as the revision ID in If-None-Match header
THEN I receive 304 HTTP response from the API
AND response headers contain the ETag header which is the most recent revision's ID

As an API user
GIVEN there is a newer version of item data than published on or before the timestamp Y
WHEN I make a GET request to /entities/items/{item_id}
AND I provide Y as a timestamp in If-Modified-Since header
THEN I receive 200 HTTP response from the API
AND response contains item data
AND response headers contain the item metadata as indicated in the specs

As an API user
GIVEN The most recent version of an item is the version published on or before the timestamp Y
WHEN I make a GET request to /entities/items/{item_id}
AND I provide Y as a timestamp in If-Modified-Since header
THEN I receive 304 HTTP response from the API
AND response headers contain the ETag header which is the most recent revision's ID

Note:

  • Per RFC 7232 versions of an item defined by revision IDs provided in If-None-Match are to be compared using the weak comparison.
  • If-None-Match accepts multiple ETags/Revision IDs. If any of them is the most recent version of the item (in weak comparison sense), the API should return 304 response
  • As only weak comparison is relevant for If-None-Match, ETags of both formats 123 and W/"123" are considered synonyms
  • timestamps must be HTTP dates as defined in RFC 7231 (see also date syntax, HttpDate class in Mediawiki REST API). Invalid dates are to be ignored - without returning errors to the client.
  • revision IDs/ETags which are not valid revisions IDs (e.g. not numbers), or are not actual revisions of the request item are to be ignored - without returning any errors to the client
  • if both If-None-Match and If-Modfied-Since, If-None-Match will be considered and If-Modified-Since ignored

Event Timeline

Change 773447 had a related patch set uploaded (by WMDE-leszek; author: WMDE-leszek):

[mediawiki/extensions/Wikibase@master] REST: Added If-None-Match and If-Modified-Since headers to get item

https://gerrit.wikimedia.org/r/773447

To specify: errors on invalid formats; which date format is expected
Strong comparison case estimate: 5
Weak comparison to become a separate story.

WMDE-leszek set the point value for this task to 5.

From task breakdown:

Subtask 1: Return 304 if the given etag is equal to the item revision id

  • parse header as an integer, compare to latest rev id
  • respond per spec with last modified and etag headers

Subtask 2: Return 304 if given a date with If-Modified-Since is equal to or later than the time of the revision creation

  • ignore If-Modified-Since if also given If-None-Match
  • respond per spec with last modified and etag headers

Questions to clarify by PM:

  • We're worried that people might send us lists. Should we really ignore lists (for now)?
  • Should we somehow prepare for accepting etags with the "weak comparison" indicator? Attempt to parse it as an int? Treat it like nonsense input?

Note for PM:

A recipient MUST ignore the If-Modified-Since header field if the received field-value is not a valid HTTP-date, or if the request method is neither GET nor HEAD.

from https://httpwg.org/specs/rfc7232.html#header.if-none-match

WMDE-leszek changed the point value for this task from 5 to 8.Mar 31 2022, 1:34 PM

Change 776161 had a related patch set uploaded (by Jakob; author: Jakob):

[mediawiki/extensions/Wikibase@master] REST: Handle conditional requests

https://gerrit.wikimedia.org/r/776161

Change 776161 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] REST: Handle conditional requests

https://gerrit.wikimedia.org/r/776161

Change 778288 had a related patch set uploaded (by Ollie Shotton; author: Ollie Shotton):

[mediawiki/extensions/Wikibase@master] REST: Fix e2e tests after OpenAPI spec created

https://gerrit.wikimedia.org/r/778288

Change 778289 had a related patch set uploaded (by Ollie Shotton; author: Ollie Shotton):

[mediawiki/extensions/Wikibase@master] REST: Fix e2e test not matching description

https://gerrit.wikimedia.org/r/778289

Change 778294 had a related patch set uploaded (by Ollie Shotton; author: Ollie Shotton):

[mediawiki/extensions/Wikibase@master] Add 304 Not Modified test to OpenAPI validation

https://gerrit.wikimedia.org/r/778294

Change 778288 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] REST: Make e2e tests pass OpenAPI spec validation

https://gerrit.wikimedia.org/r/778288

Change 778294 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] REST: 304 Not Modified OpenAPI validation test

https://gerrit.wikimedia.org/r/778294

Change 778289 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] REST: Fix e2e test not matching description

https://gerrit.wikimedia.org/r/778289