View our GitHub

Please visit sails-docs on GitHub to view documentation on your mobile device.

Edit Page

Response (res)

Overview

Sails is built on Express, and uses Node's HTTP server conventions. Because of this, you can access all of the Node and Express methods and properties on the res object whereever it is accessible (i.e. in your controllers, policies, and custom responses.)

A nice side effect of this compatibility is that, in many cases, you can paste existing Node.js code into a Sails app and it will work. And since Sails implements a transport-agnostic request interpreter, the code in your Sails app is WebSocket-compatible as well.

Sails adds a few methods of its own to the res object, like res.view(). These features are syntactic sugar on top of the underlying implementation, and also support both HTTP and WebSockets.

Protocol Support

The chart below describes support for the methods and properties on the Sails Request object (req) across multiple transports:

The chart below describes support for the methods and properties on the Sails Response object (res) across multiple transports:

HTTP WebSockets
res.status()
res.set()
res.get()
res.cookie()
res.clearCookie()
res.redirect()
res.location()
res.charset
res.send()
res.json()
res.jsonp()
res.type()
res.format()
res.attachment()
res.sendfile()
res.download()
res.links()
res.locals
res.render()
res.view()

Legend

  • - fully supported
  • - feature not yet implemented
  • - unsupported due to protocol restrictions

Is something missing?

If you notice something we've missed or could be improved on, please follow this link and submit a pull request to the sails-docs repo. Once we merge it, the changes will be reflected on the website the next time it is deployed.

Reference

We wrote a book!

Get early access to the book
with promotion code: mcneildoc

Get the Book