Skip to content

Latest commit

 

History

History
64 lines (51 loc) · 3.7 KB

File metadata and controls

64 lines (51 loc) · 3.7 KB

Request (req)

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 req 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 and properties of its own to the req object, like req.wantsJSON and req.params.all(). 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:

HTTP WebSockets
req.file()
req.param()
req.route
req.cookies
req.signedCookies
req.get()
req.accepts()
req.accepted
req.is()
req.ip
req.ips
req.path
req.host
req.fresh
req.stale
req.xhr
req.protocol
req.secure
req.session
req.subdomains
req.method
req.originalUrl
req.acceptedLanguages
req.acceptedCharsets
req.acceptsCharset()
req.acceptsLanguage()
req.isSocket
req.params.all()
req.socket.id ✖️
req.socket.join ✖️
req.socket.leave ✖️
req.socket.broadcast ✖️
req.transport
req.url
req.wantsJSON

Legend

  • ✅ - fully supported
  • ⬜ - feature not yet implemented
  • ✖️ - unsupported due to protocol restrictions