Page MenuHomePhabricator

🟧 Allow requesting subset of fields of item data to be returned by the GET /entities/items/{item_id} REST API
Closed, ResolvedPublic5 Estimated Story Points

Description

As a developer of an application I want to specify which item fields I want to get from the API, so that I do not need to parse through unwanted fields

Allowed values of the _fields parameter:

  • type
  • labels
  • descriptions
  • aliases
  • statements
  • sitelinks

ID is always included in the response.

BDD

WHEN I request GET /entities/items/{item_id}
AND provide the _fields parameter containing allowed field names
THEN I get 200 HTTP response
AND response contains serialization of the item data following the specification, including ID and only the fields I have requested
AND headers of the response include the headers as defined in the specification

WHEN I request GET /entities/items/{item_id}
AND provide the _fields parameter including the value which is not allowed
THEN I get 400 HTTP response
AND it contains a invalid-field code and a message "Not a valid field: {field}"
AND a HTTP header Content-Language set to en

Not included in this story

  • internationalized/translated error message via Accept-Language HTTP header

See Gerrit patch 770445 for the _fields parameter specification

Event Timeline

WMDE-leszek renamed this task from Allow defining which data fields should be returned by the GET /entities/items/{item_id} REST API to Allow requesting subset of fields of item data to be returned by the GET /entities/items/{item_id} REST API.Feb 22 2022, 11:40 AM
Silvan_WMDE set the point value for this task to 5.Mar 3 2022, 2:55 PM

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

[mediawiki/extensions/Wikibase@master] REST: Added specs for _fields param of GET /entities/items/{item_id}

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

Task Breakdown Notes:

T303919: 🟧 Filter item data by input from the _fields request parameter

  • in the RouteHandler, construct the GetItemRequest object based on both the ItemId and the _fields request parameter
  • in the GetItem use case, filter the itemSerialization based on the _fields from the GetItemRequest
    • create a new GetItemFieldsFilter object that filters the itemSerialization based on requested fields
  • since it is an array, the filtered ItemSerialization can still be passed into GetItemResult

T303916: 🟧 Handle error when `_fields` parameter includes an invalid value

  • use the validator to return a new "Failure" GetItemResult (with isSuccessful() == false)
  • the RouteHandler will create an error response (set http status, code, message) based on the GetItemResult
Ollie.Shotton_WMDE renamed this task from Allow requesting subset of fields of item data to be returned by the GET /entities/items/{item_id} REST API to 🟧 Allow requesting subset of fields of item data to be returned by the GET /entities/items/{item_id} REST API.Mar 16 2022, 8:58 AM

Change 770445 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] REST: Added specs for _fields param of GET /entities/items/{item_id}

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

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

[mediawiki/extensions/Wikibase@master] REST: Use comma separator in _field query param

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

Change 774869 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] REST: Use comma separator in _field query param

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