Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fcouceiro/socket-rest
A router for socket.io that handles events in a RESTful style
https://github.com/fcouceiro/socket-rest
nodejs router socket-communication socket-io
Last synced: 21 days ago
JSON representation
A router for socket.io that handles events in a RESTful style
- Host: GitHub
- URL: https://github.com/fcouceiro/socket-rest
- Owner: fcouceiro
- License: mit
- Created: 2017-09-14T18:55:21.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-11-20T11:21:23.000Z (about 7 years ago)
- Last Synced: 2024-04-24T00:39:25.537Z (10 months ago)
- Topics: nodejs, router, socket-communication, socket-io
- Language: JavaScript
- Homepage:
- Size: 20.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# socket-rest
[![Build Status](https://travis-ci.org/fcouceiro/socket-rest.svg?branch=master)](https://travis-ci.org/fcouceiro/socket-rest)
[![Coverage Status](https://coveralls.io/repos/github/fcouceiro/socket-rest/badge.svg)](https://coveralls.io/github/fcouceiro/socket-rest)A router for socket.io that handles events in a RESTful style
## Installation
`npm install socket-rest`
## Usage
### Server
var socketRest = require('socket-rest')();// Register socket rest router as socket.io middleware
io.use(socketRest.router);// Use express-like router methods to define your routes
socketRest.put('/users/:id/photos/:photoId', function (req, socket) {
console.log(req); // req will have path params and query params
});// Use the socket instance to emit-back to clients
socketRest.delete('/users/:id', function (req, socket, isSoftDelete) {
socket.emit('user:deleted', req.params.id);
});### Client
// Suffix the route with a verb expression
socket.emit('/users/2/delete', true); // isSoftDelete will be true
### Verb expressionsThe verb can be specified by suffixing the route with a verb expression. Several verb expressions can translate to one HTTP verb:
| Verb expressions | HTTP Verb |
|------------------|-----------|
| get, read | GET |
| post, create | POST |
| put, update | PUT |
| delete | DELETE |
## Tests
`npm test`
## Contributing
In lieu of a formal style guide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.