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
Copy file name to clipboardExpand all lines: docs/api-guidelines/pagination-filtering-sorting.md
+90Lines changed: 90 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -233,3 +233,93 @@ components:
233
233
value: nhsNumber|asc,type|desc
234
234
summary: Sort by multiple fields
235
235
```
236
+
237
+
## Field Selection
238
+
239
+
**SHOULD** support a `fields` query parameter to allow clients to specify which fields should be included in the JSON response.
240
+
241
+
This improves performance by reducing payload size and network transfer time, and enhances usability for consumers who don't need the full object representation.
242
+
243
+
### Query Parameter
244
+
245
+
- `fields`: A comma-separated list of field names to include in the response.
246
+
247
+
### Examples
248
+
249
+
#### Basic field selection
250
+
251
+
```text
252
+
GET /api/widgets?fields=id,name,createdAt
253
+
```
254
+
255
+
Returns only the specified fields:
256
+
257
+
```json
258
+
{
259
+
"results": [
260
+
{
261
+
"id": "de750613-ef3c-4f5d-8148-10308b91896c",
262
+
"name": "Widget Example",
263
+
"createdAt": "2024-01-15T10:30:00Z"
264
+
}
265
+
]
266
+
}
267
+
```
268
+
269
+
#### Combining with other parameters
270
+
271
+
```text
272
+
GET /api/widgets?fields=id,name,status&status=active&limit=5
273
+
```
274
+
275
+
#### All fields (default behavior)
276
+
277
+
When the `fields` parameter is omitted, all fields are returned:
278
+
279
+
```text
280
+
GET /api/widgets
281
+
```
282
+
283
+
### Behavior
284
+
285
+
**SHOULD** implement the following behavior for the `fields` parameter:
286
+
287
+
- **Valid fields**: Include only the requested fields in the response
288
+
- **Invalid field names**: Ignore invalid field names silently and include only valid ones
289
+
- **Empty fields parameter**: Return all fields (same as omitting the parameter)
290
+
- **Case sensitivity**: Field names should be case-sensitive
291
+
- **Nested fields**: Support dot notation for nested objects (e.g., `metadata.total`)
292
+
293
+
```yaml
294
+
components:
295
+
parameters:
296
+
fieldsParam:
297
+
in: query
298
+
name: fields
299
+
required: false
300
+
description: |
301
+
Comma-separated list of fields to include in the response.
302
+
303
+
Behaviour:
304
+
- Valid fields: include only the requested fields in the response.
305
+
- Invalid field names: ignore silently and include only valid ones.
306
+
- Empty fields parameter: return all fields (same as omitting the parameter).
307
+
- Case sensitivity: field names are case-sensitive.
308
+
- Nested fields: support dot notation for nested objects (e.g., `metadata.total`).
0 commit comments