Cert++
Close

Rendering an ISML template versus returning a JSON response

Key Takeaway

Call res.render to send an HTML page built from an ISML template. Call res.json to send a JSON object with Content-Type: application/json, which suits an AJAX endpoint that client-side scripts call.

Every SFRA controller route ends by sending a response back to the client. The method you call on res decides what kind of response the client gets. res.render sends an ISML template, which B2C Commerce turns into an HTML page using the data you pass in. res.json sends a JSON object instead, so a client-side script gets data rather than a page.

Controllers and ViewModels

A controller handles the request, builds ViewModels and produces the response. A script API object sometimes behaves like a Java object. A ViewModel turns script API objects into a pure JSON object. One ViewModel often combines data from several script objects.

B2C Commerce Developer Study Guide

Checklist progress

0/237Learned

Given a requirement, create and extend the functionality of a JavaScript controller that leverages models, decorators, factories, or helpers following API best practices, and renders a template or returns a JSON response

0/11

Prepare for the Exam

Play Today's Certle

Study Community

Ask questions and get the latest info from other B2C Commerce Developer studiers. 796 members and growing.