commercetools-sunrise-java
commercetools-sunrise-java copied to clipboard
Demo case content negotiation for JSON (AJAX) and HTML
- http://www.playframework.com/documentation/2.3.x/JavaContentNegotiation
- https://gist.github.com/schleichardt/4e84b6136c81ae317b0e
public Result index() {
return result(OK).
json(() -> Json.parse("{\"foo\":\"bar\"}")).
html(() -> index.render(data().build()));
}
@lauraluiz I think this approach is better than action composition since there are no surprises in the background/it is obvious that the endpoint supports JSON and HTML and in addition the JSON stuff or the HTML stuff will be only executed if needed.
This is only nice possible with Java 8.
+1
Yep, it looks really nice. I'm glad that you found a way to support this nicely! :)
We have to see how Sunrise will work like, but let's have this in mind. This is not necessary if we want to reload for every change to optimize SEO, of course.