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.