Back to Sails

`io.socket.put()`

docs/reference/websockets/sails.io.js/socket.put.md

12.12.20001.6 KB
Original Source

io.socket.put()

Send a socket request (virtual PUT) to a Sails server using Socket.IO.

js
io.socket.put(url, data, function (resData, jwres){
  // ...
});

Usage

ArgumentTypeDetails
1url((string))The destination URL path, e.g. "/checkout".
2data((json?))Optional request data. If provided, it will be JSON-encoded and included as the virtual HTTP body.
3callback((function?))Optional callback. If provided, it will be called when the server responds.
Callback
ArgumentTypeDetails
1resData((json))Data received in the response from the Sails server (=== jwres.body, equivalent to the HTTP response body).
2jwres((dictionary))A JSON WebSocket Response object. Has headers, a body, and a statusCode.

Example

html
<script>
io.socket.put('/users/9', { occupation: 'psychic' }, function (resData, jwr) {
  resData.statusCode; // => 200
});
</script>

Notes

  • Remember that you can communicate with any of your routes using socket requests.
  • Need to customize request headers? Check out the slightly lower-level io.socket.request() method. To set custom headers for all outgoing requests, check out io.sails.headers.
<docmeta name="displayName" value="io.socket.put()"> <docmeta name="pageType" value="method">