-
Notifications
You must be signed in to change notification settings - Fork 15
What is a Partial Response?
By default, the server will send back the full representation of a rest resource for every request. Partial responses let you request only the elements you are interested in, instead of the full resource representation. This allows your client application to avoid transferring, parsing, and storing unneeded fields, so you can utilize network and memory resources more efficiently.
For example, take the two responses below. Both are requests for the same resource, but let's assume we are only interested in the following fields:
- Product Name
- List Price
- Image Url for Thumbnail Images Only
https://www.catnap.it/products/12345/details
{
"id": "12345,
"name": "Product 1",
"prices": {
"list": "$120.00",
"sale": "$89.99
},
"images": [
{
"sortOrder": 1,
"url": "https://catnap-springboot-sample.herokuapp.com/12345-primary.png",
"alt": "Product 1",
"size": "primary"
},
{
"sortOrder": 2,
"url": "https://catnap-springboot-sample.herokuapp.com/12345-thumbnail.png",
"alt": "Product 1",
"size": "thumbnail"
}
]
}
https://www.catnap.it/products/12345/details?fields=name,prices(list),images(url)[size=thumbnail]
{
"name": "Product 1",
"prices": {
"list": "$120.00"
},
images: [
{
"url": "https://catnap-springboot-sample.herokuapp.com/12345-thumbnail.png"
}
]
}
As you can see the partial response is a significant reduction in payload size and message complexity. By allowing the consumer of the API to specify the fields they are interested in you can significantly reduce the complexity of response messages as well as improve performance over the wire.