Skip to content
Greg Whitaker edited this page Jul 27, 2016 · 18 revisions

Catnap is a framework for supporting partial JSON and JSONP responses in RESTful web services by allowing users to supply arbitrary queries in the URL.

Catnap supports partial responses in the following web frameworks:

  • Spring Boot
  • SpringMVC
  • RESTEasy
  • Jersey

##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

###Full Resource Representation http://domain/product/12345/details

{
	"id": "12345",
	"name": "Product 1",
	"prices": {
    	"listPrice": "$120.00",
    	"salePrice: "$89.99"
	},
	images: [
    	{
        	"sortOrder": 1,
        	"url": "http://domain/images/product/12345/primary.png",
        	"alt": "Product 1",
        	"size": "primary"
    	},
    	{
        	"sortOrder": 2,
        	"url": "http://domain/images/product/12345/thumbnail.png",
        	"alt": "Product 1",
        	"size": "thumbnail"
    	}
	]
}

###Partial Resource Representation http://domain/product/12345/details?fields=name,prices(listPrice),images(url)[size=thumbnail]

{
	"name": "Product 1",
	"prices": {
    	"listPrice": "$120.00",
	},
	images: [
    	{
        	"url": "http://domain/images/product/12345/thumbnail.png",
    	}
	]
}
Clone this wiki locally