REST API Request and Response Patterns

JSON request bodies, envelope choices, sparse fieldsets, includes, concurrency control, and common response contracts.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

JSON request patterns

Shape JSON bodies consistently for creates and updates.

Simple create request body

POST a resource representation.

jsonANYrestjsoncreate
json
{
  "name": "Ava Martin",
  "email": "ava@example.com",
  "role": "admin"
}
Notes

A clean top-level object is often enough for private APIs and straightforward CRUD designs.

Partial update body

PATCH with only the fields that change.

jsonANYrestpatchjson
json
{
  "timezone": "America/Los_Angeles",
  "marketing_opt_in": false
}
Notes

Small patch bodies minimize payload size and avoid accidental overwrites.

Bulk create request

Submit multiple items in one call when needed.

jsonANYrestbulkjson
json
{
  "items": [
    { "sku": "sku_1", "qty": 2 },
    { "sku": "sku_2", "qty": 1 }
  ]
}
Notes

Bulk endpoints can reduce chattiness, but they need clear per-item success and failure semantics.

Response shaping

Support flexible reads without proliferating endpoints.

Sparse fieldsets

Return only requested fields.

httpANYrestfieldsprojection
http
GET /users/usr_123?fields=id,name,email
Notes

Sparse fieldsets reduce overfetching for large objects and mobile clients.

Return an ETag for concurrency and caching

Tag a representation with a revision validator.

httpANYrestetagconcurrency
http
ETag: "686897696a7c876b7e"
Notes

ETags can power both conditional caching and optimistic concurrency checks.

Protect updates with If-Match

Prevent lost updates from concurrent writes.

httpANYrestif-matchoptimistic-locking
http
PATCH /documents/doc_123
If-Match: "686897696a7c876b7e"
Notes

If the entity tag no longer matches, the API can reject the write and ask the client to refetch.

Represent async work as a job resource

Queue work and let clients poll job state.

jsonANYrestasyncjobs
json
{
  "id": "job_123",
  "status": "queued",
  "url": "/jobs/job_123"
}
Notes

This pattern works well when a request takes too long to finish within a normal synchronous response window.

Recommended next

No recommendations yet.