Skip to content

ashermanwmf/RestfulSocket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Welcome to RestfulSocket

RestfulSocket is a RESTful Socket that combines the native Fetch, Websocket and Promise API to create a restful response to a websocket event listener.

Getting Started

  1. Install RestfulSocket: (COMING SOON)
npm install -save restfulsocket
  1. Import RestfulSocket:
import RestfulSocket from 'restfulsocket'
  1. Use RestfulSocket:
const onopen = () =>{ /* Function for socket on open */ };
const onclose = () =>{ /* Function for socket on close */ };
const onerror = () =>{ /* Function for socket on error* /};

const restSocket = new RestfulSocket('ws://localhost/', onopen, onclose, onerror);

restSocket.findSocketMessage((socketMessageData) =>{
  /* define a filter to find and return socket message from socketMessageData object */
});

restSocket.get('localhost/api/initialData', requestObjectOne)
  .on('sampleMessage')
  .then((data) => {
    //DATA is an array of objects returned from fetch promises
  })
  .catch(console.log);
  1. Complex use case:
const restSocket = new RestfulSocket('ws://localhost/', onopen, onclose, onerror);

restSocket.findSocketMessage((socketMessageData) =>{
  /* define a filter to find and return socket message from socketMessageData object */
});

restSocket.get('localhost/api/initialData', requestObjectOne)
  .post('localhost/api/initialPost', requestObjectTwo)
  .on('init')
  .then((data) => {
    //DATA is an array of objects returned from fetch promises
  })
  .catch(console.log);

restSocket.get('localhost/api/updateData', requestObjectThree)
  .get('localhost/api/secondaryData', requestObjectFour)
  .on('update')
  .then((data) => {
    //DATA is an array of objects returned from fetch promises
  })
  .catch(console.log);

About

A package to make HTTP requests on WebSocket 'onmessage' listener events.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published