Edit Page
io.socket.post()
Send a socket request (virtual POST) to a Sails server using Socket.io.
io.socket.post(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, will be JSON-encoded and included as the virtual HTTP body. |
3 |
callback |
|
Optional callback- if provided, will be called when the server responds. |
Callback
|
Argument |
Type |
Details |
1 |
resData |
|
Data received in the response from the Sails server (=== jwres.body , and also equivalent to the HTTP response body.) |
2 |
jwres |
|
A JSON WebSocket Response object. Has headers , a body , and a statusCode . |
Example
<script>
io.socket.post('/users', { name: 'Timmy Mendez' }, function (resData, jwRes) {
jwRes.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, or 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.