commercetools-sunrise-java icon indicating copy to clipboard operation
commercetools-sunrise-java copied to clipboard

Demo case content negotiation for JSON (AJAX) and HTML

Open schleichardt opened this issue 10 years ago • 3 comments

  • 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.

schleichardt avatar Jul 01 '14 23:07 schleichardt

+1

svenmueller avatar Jul 02 '14 08:07 svenmueller

Yep, it looks really nice. I'm glad that you found a way to support this nicely! :)

lauraluiz avatar Jul 03 '14 08:07 lauraluiz

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.

lauraluiz avatar Apr 20 '15 09:04 lauraluiz