rest-io-client
v0.2.0
Published
Promise based rest-io-router client socket implementation
Downloads
3
Readme
rest-io-client
Client es6 class for Promise based websocket requests to server implementing rest-io-router
Installation
With node [installed]:
$ npm install rest-io-client --save
Usage
import RestSocket from 'rest-io-client'
/*
class RestSocket
params:
url: required
options: optional socket.io options object
*/
var socket = new RestSocket(url)
socket.get("/users").then(data => {
...
})
API
get(url[, params, query]).then(data => {..}).catch(err => {...})
post(url[, params, query]).then(data => {..}).catch(err => {...})
put(url[, params, query]).then(data => {..}).catch(err => {...})
delete(url[, params, query]).then(data => {..}).catch(err => {...})
*Note*
params = any valid js object
query = any valid js object
url may also contain query strings as below
get("/users?id=foo").then(.....
Emitting/Receiving via socket.io
import RestSocket from 'rest-io-client'
var socket = new RestSocket(url)
socket.on('foo', msg => {...})
socket.emit('bar', data)
*Note Reserved for Promise based API*
socket.on('rest',...
socket.emit('rest',...