Skip to content

Field Selection

One reason teams reach for GraphQL is over-fetching: an endpoint returns 30 fields when the client needs 3. REST can offer the same control with two simple query parameters.

Let the client list the fields it wants with ?fields=:

GET /articles?fields=id,title

The server returns only those keys. This shrinks payloads for mobile clients and list views, and documents intent. Always include the resource’s identifier even if not requested, so responses stay addressable.

By default, link to related resources rather than embedding them. When a client wants them inline, let it opt in with ?expand=:

GET /articles/42?expand=author

Without expand, author is a reference ({ "id": 7, "href": "/users/7" }); with it, the author object is embedded. This keeps the default response small while avoiding an extra round trip when the client genuinely needs the related data.

JavaScript
What does `?fields=id,title` request?
What is the purpose of an `?expand=author` parameter?
Why always include the identifier even if not in `fields`?