This example shows you how to configure Catnap view rendering with the Spring Boot web framework.
Start the example by running the following command:
$ ./run.sh
This example application exposes the following API for retrieving information about Widgets.
Catnap allows consumers a great deal of flexibility to return only the data in which they are interested. The example API calls below illustrate the power of Catnap. Feel free to play around with the examples and come up with your own Catnap queries.
This example will only retrieve the name of the widget and all of its images.
{
"name": "Widget 1",
"images": [
{
"sortOrder": 1,
"url": "http://gregwhitaker.github.com/catnap/widgets/1/images/large.png",
"alt": "Widget 1 Large",
"type": "large"
},
{
"sortOrder": 2,
"url": "http://gregwhitaker.github.com/catnap/widgets/1/images/medium.png",
"alt": "Widget 1 Medium",
"type": "medium"
},
{
"sortOrder": 3,
"url": "http://gregwhitaker.github.com/catnap/widgets/1/images/thumbnail.png",
"alt": "Widget 1 Thumbnail",
"type": "thumbnail"
}
]
}
This example will only retrieve the name of the widget, the formatted list price, and the formatted sale price.
{
"name": "Widget 1",
"prices": {
"formattedList": "$35.99",
"formattedSale": "$30.00"
}
}
This example will only retrieve the name of the widget and the url of the thumbnail image for the widget.
{
"name": "Widget 1",
"images": [
{
"url": "http://gregwhitaker.github.com/catnap/widgets/1/images/thumbnail.png"
}
]
}
This example will only retrieve the name of the widget and the urls of images that have a sortOrder greater than or equal to 2.
[
{
"name": "Widget 1",
"images": [
{
"url": "http://gregwhitaker.github.com/catnap/widgets/1/images/medium.png"
},
{
"url": "http://gregwhitaker.github.com/catnap/widgets/1/images/thumbnail.png"
}
]
},
{
"name": "Widget 2",
"images": [
{
"url": "http://gregwhitaker.github.com/catnap/widgets/2/images/thumbnail.png"
}
]
},
{
"name": "Widget 3",
"images": [
{
"url": "http://gregwhitaker.github.com/catnap/widgets/3/images/medium.png"
},
{
"url": "http://gregwhitaker.github.com/catnap/widgets/3/images/thumbnail.png"
}
]
}
]
You can customize the JSON rendering using the the Jackson ObjectMapper customizations provided by spring-boot.
See "Customize the Jackson ObjectMapper" section in Spring Boot documentation.
- Display dates as timestamps
- Display dates as strings (UTC)