As of 2022-04-11, when Wikibase REST API is asked for data of an item which is a redirect to another item, requests results in 500 HTTP response containing
{"code":"unexpected-error","message":"Unexpected error"}
Instead, the API should recognize the redirect, and point the client to the relevant resource.
BDD
GIVEN Q123 is a redirect to Q321
WHEN I make a GET request to /entities/items/Q123
THEN I receive 308 HTTP response from the API
AND Location header in the response includes the absolute path of the /entities/items/Q321 resource
AND response body is empty
GIVEN Q123 is a redirect to Q321
WHEN I make a GET request to /entities/items/Q123
AND provide _fields=labels parameter to only get labels of an item
THEN I receive 308 HTTP response from the API
AND Location header in the response includes the absolute path of the /entities/items/Q321 resource
AND the path in the response also includes _fields=labels parameter
AND response body is empty
Note:
- if a user has no permission to get item data, they should get unauthorized access error not a 308 response
- FWIW, passing all query paremeter to the Location header is okay from the point of view of that story
- for url/location generation that method might of relevance: https://github.com/wikimedia/mediawiki/blob/master/includes/Rest/Router.php#L267
- Absolute path is to be used per HTTP standard https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30
Open question: what should happen with query parameters, are they included in the Location header in the response, or is the "raw" URL returned - @WMDE-leszek to define