Many REST APIs return different response *types* based on result count #107
Labels
Issue-Bug
Issue-Feature
Complex enough to require an in depth planning process and actual budgeted, scheduled work.
Brief description of your issue
I just hit upon something in the REST api that I believe we should consider changing at the schema/interface level. Some of the APIs return different result types depending on the count of items returned, for example:
Either No Content (null), a single object, or an array. For example:
This returns an array:
.../api/packages/Microsoft.PowerToys/versions
This returns a single object:
.../api/packages/Zwift.Zwift/versions
This returns 204 (null):
.../api/packages/Foo.Bar/versions
If the query returns more than one result, I get an object where Data is an array (and there’s a continuationToken property), but if there’s only one result, then Data is an object. This is true for the packages, packageManifests, locales, installers and versions APIs.
IMO this is a bad practice and requires clients to try to parse the result object twice in a catch block to successfully deserialize it. Instead we should always consistently return the same object type, potentially with only one item in the array, and a null continuationToken.
Steps to reproduce
Call above APIs
Expected behavior
Response type should be consistent regardless of # of results
Actual behavior
Response type varies based on number of results
Environment
The text was updated successfully, but these errors were encountered: