Giter Club home page Giter Club logo

sails-socket's Introduction

Sails Socket

A Promise-based implementation of Sails Socket library inspired by axios.

Install

simply install it with node or yarn:

npm install sails-socket

Usage

You have to provide socket url to the connect method and you're off to go.

import SailsSocket from 'sails-socket'
...

SailsSocket.connect('http://your-socket-server/');
SailsSocket.get('/hello').then(function(jwr) {
  console.log(jwr.body);
}).catch(function(jwr) {
  console.log(jwr.error);
})

API

The implemented methods are: connect, disconnect, get, post, put, delete, request, on, off, setHeader

connect

It has to be called before using any other functions, it would throw an error if there was already another socket connection.

const initializeParams = {url: 'http://sails-server.com/'}
socket = SailsSocket.connect(initializeParams)

initializeParams can be any sails configuration option as an objec like url, transports, headers and etc. see sails documentations for more details. it returns the created socket. although it can be accessible later via static SailsSocket.activeSocket property.

disconnect

it disconnects current active socket.

SailsSocket.disconnect()

get

it sends a get request corresponding to io.socket.get() and returns a promise.

SailsSocket.get(url, data)

post

it sends a post request corresponding to io.socket.post() and returns a promise.

SailsSocket.post(url, data)

put

it sends a put request corresponding to io.socket.put() and returns a promise.

SailsSocket.put(url, data)

delete

it sends a delete request corresponding to io.socket.delete() and returns a promise.

SailsSocket.delete(url, data)

request

it sends a customizable request corresponding to io.socket.request() and returns a promise.

SailsSocket.request(options)

on

it starts listening for server-sent events from Sails with specified eventIdentity corresponding to io.socket.on().

SailsSocket.on(url, callback)

off

unbind the specified event handler corresponding to io.socket.off().

SailsSocket.off(url, callback)

setHeader

sets header to the active socket

SailsSocket.setHeader(headers)

headers object

Contributions

please check for closed issues before opening new issues.

sails-socket's People

Contributors

thg303 avatar

Watchers

James Cloos avatar Mohammad javad Masoudian avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.