Skip to content

Commit 4c54583

Browse files
authored
Change per Issue #217 recommendations (#218)
* Empty Collection Recommendations based on #217 Service providers are unclear if they should return 404s when collection searches have no results. Per the advice in the issue 217 thread the recommendation is to NOT return a 404 in these cases and instead maintain consistency in their response and signifying no results as _value_ containing an empty array. "We would always say that should return a 200 with an empty collection. The call succeeded, the collection exists. There's just nothing in it. Given we always follow the convention of having the array itself be a 'value' property on a top-level object representing the collection itself, there's also the ability to return collection metadata that is valid regardless of whether there is anything in the collection, e.g. MaxItems." -- Gareth Jones * TOC formatting moving to a new section. 9.10. * typo and lower case property name
1 parent e0ba179 commit 4c54583

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Guidelines.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ This document establishes the guidelines Microsoft REST APIs SHOULD follow so RE
8484
- [9.8.2. Client-driven paging](#982-client-driven-paging)
8585
- [9.8.3. Additional considerations](#983-additional-considerations)
8686
- [9.9. Compound collection operations](#99-compound-collection-operations)
87+
- [9.10. Empty Results](#910-empty-results)
8788
- [10. Delta queries](#10-delta-queries)
8889
- [10.1. Delta links](#101-delta-links)
8990
- [10.2. Entity representation](#102-entity-representation)
@@ -1006,6 +1007,27 @@ When these operations are performed together, the evaluation order MUST be:
10061007
2. **Sorting**. The potentially filtered list is sorted according to the sort criteria.
10071008
3. **Pagination**. The materialized paginated view is presented over the filtered, sorted list. This applies to both server-driven pagination and client-driven pagination.
10081009

1010+
### 9.10. Empty Results
1011+
When a filter is performed on a collection and the result set is empty you MUST respond with a valid response body and a 200 response code.
1012+
In this example the filters supplied by the client resulted in a empty result set.
1013+
The response body is returned as normal and the _value_ attribute is set to a empty collection.
1014+
A client MAY be expecting metadata attributes like _maxItems_ based on the format of your responses to similar calls which produced results.
1015+
You SHOULD maintain consistency in your API whenever possible.
1016+
1017+
```http
1018+
GET https://api.contoso.com/v1.0/products?$filter=(name eq 'Milk' or name eq 'Eggs') and price lt 2.55
1019+
Accept: application/json
1020+
1021+
HTTP/1.1 200 OK
1022+
Content-Type: application/json
1023+
1024+
{
1025+
...,
1026+
"maxItems": 0,
1027+
"value": []
1028+
}
1029+
```
1030+
10091031
## 10. Delta queries
10101032
Services MAY choose to support delta queries.
10111033

0 commit comments

Comments
 (0)