Updated includes example¶
This example combines relationship updates with include to return expanded payloads in one call.
Example flow¶
- Update customer attributes and relationships.
- Pass
include=computersto receive updated related resources immediately. - Read both
dataandincludedin one round-trip.
PATCH /customers/1?include=computers
Content-Type: application/json
{
"data": {
"type": "customer",
"id": "1",
"attributes": {
"name": "John Updated"
},
"relationships": {
"computers": {
"data": [{"type": "computer", "id": "10"}]
}
}
}
}
import httpx
payload = {
"data": {
"type": "customer",
"id": "1",
"attributes": {"name": "John Updated"},
"relationships": {
"computers": {
"data": [{"type": "computer", "id": "10"}],
},
},
},
}
response = httpx.patch("http://localhost:8000/api/customers/1?include=computers", json=payload)
print(response.json())
Example response excerpt:
{
"links": {"self": "http://localhost:8000/api/customers/1?include=computers"},
"data": {
"type": "customer",
"id": "1",
"links": {"self": "http://localhost:8000/api/customers/1/"}
},
"included": [
{
"type": "computer",
"id": "10",
"attributes": {"serial": "ABC-123"},
"links": {"self": "http://localhost:8000/api/computers/10/"}
}
]
}
Use this pattern when clients need immediate post-update relationship context.