Back to Sails

`io.socket.get()`

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

12.12.20001.7 KB
Original Source

io.socket.get()

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

js
io.socket.get(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 URL-encoded and appended to url (existing query string params in url will be preserved).
3callback((function?))Optional callback. If provided, it will be called when the server responds.
Callback
ArgumentTypeDetails
1resData((json))Data, if any, sent in the response from the Sails server. This is the same thing as jwres.body.
2jwres((dictionary))A JSON WebSocket response, which consists of headers (a ((dictionary))), body (((json))), and statusCode (a ((number))).

Example

html
<script>
io.socket.get('/users/9', function (resData) {
  // resData => {id:9, name: 'Timmy Mendez'}
});
</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.get()"> <docmeta name="pageType" value="method">