Edit Page
io.socket.get()
Send a socket request (virtual GET) to a Sails server using Socket.IO.
io.socket.get(url, data, function (resData, jwres){
// ...
});
Usage
|
Argument |
Type |
Details |
1 |
url |
|
The destination URL path, e.g. "/checkout". |
2 |
data |
|
Optional request data. If provided, it will be URL-encoded and appended to url (existing query string params in url will be preserved). |
3 |
callback |
|
Optional callback. If provided, it will be called when the server responds. |
Callback
|
Argument |
Type |
Details |
1 |
resData |
|
Data, if any, sent in the response from the Sails server. This is the same thing as jwres.body . |
2 |
jwres |
|
A JSON WebSocket response, which consists of headers (a ), body (), and statusCode (a ). |
Example
<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
.
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.