commercetools / commercetools-sunrise-java

The next generation shop framework by commercetools
https://demo.commercetools.com
Apache License 2.0
46 stars 35 forks source link

Demo case content negotiation for JSON (AJAX) and HTML #44

Open schleichardt opened 10 years ago

schleichardt commented 10 years ago
    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.

svenmueller commented 10 years ago

+1

lauraluiz commented 10 years ago

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

lauraluiz commented 9 years ago

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.