You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 5bcb823
Browse filesBrowse the repository at this point in the historyBrowse files
Voeg regel toe voor het altijd teruggeven van objecten (#354)
Deze suggestie kwam naar voren tijdens de brainstorm sessie over
pagination. De regel is breder toepasbaar dan enkel pagination en
bij meerdere API's is deze verandering toegepast nadat bleek dat
er behoefte was aan metadata. Ook is dit voor linked data belangrijk
zodat ook API's beter integreren met linked data.
Co-authored-by: Alexander Green <alexander.green@logius.nl>
108:44 error nlgov:always-return-objects The content of all responses should be wrapped in an object paths./incorrect.get.responses[200].content.application/json.schema.type
4
+
113:44 error nlgov:always-return-objects The content of all responses should be wrapped in an object paths./incorrect.get.responses[200].content.application/hal+json.schema.type
5
+
118:44 error nlgov:always-return-objects The content of all responses should be wrapped in an object paths./incorrect.get.responses[200].content.application/xml.schema.type
<pclass="rulelab">Always return a response with an object</p>
197
+
<dl>
198
+
<dt>Statement</dt>
199
+
<dd>
200
+
<p>A JSON or XML response MUST have a top-level object, regardless of request method.
201
+
For <a>collection resources</a>, the object MUST contain a field (its key MAY be named <code>items</code>) with its value an array of items from that collection.
202
+
</dd>
203
+
<dt>Rationale</dt>
204
+
<dd>
205
+
<p>For <a>singular resources</a>, objects are returned as part of RESTful design.
206
+
<p>For <a>collection resources</a>, items can be retrieved all at once, or a subset thereof.
207
+
In both cases, wrapping the returned items in an object allows metadata to be attached to the response.
208
+
Examples of metadata are structured data to implement linked data concepts, or pagination data for performance purposes.
209
+
<p>If a collection resource directly returns an array of object information from the collection, such metadata can only be provided using HTTP headers.
210
+
While that is feasible, HTTP headers are generally more difficult to work with than content from a response body.
211
+
<p>Even if currently no metadata is attached to a response, that could be the case in the future.
212
+
Changing the response from an array to an object is a breaking change, hence it is future-proof to always return an object.
213
+
<aside class="example">
214
+
The following example shows a response from a collection resource containing all items
0 commit comments