【Sails.js】sails.io.jsはsocketioのwrapper

qiita.com

WebSocketsを使ってRESTfulなAPIを実現したい場合は以下のように使う。 $.ajax と全く同じ構文なので馴染みやすい。これを用いることでリアルタイムアプリケーションを意識せずに構築できるようだ。

assets/js/dependencies/sails.io.js

Purpose

This file adds a few custom methods to socket.io which provide the "built-in" websockets functionality for Sails.

Specifically, those methods allow you to send and receive Socket.IO messages to & from Sails by simulating a REST client interface on top of Socket.IO. It models it's API after the $.ajax pattern from jQuery which you might be familiar with.

var socket = window.io.connect()

socket.post( url, [data], [cb] )

socket.get("/foo", function serverRespondedWith (body, jwr) { console.log(body); })