# socket-rest

> A router for socket.io that handles events in a RESTful style

Latest version **0.1.2** (published 2017-11-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install socket-rest
pnpm add socket-rest
yarn add socket-rest
bun add socket-rest
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2017-11-20 |
| First published | 2017-09-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Francisco Couceiro |
| Maintainers | fcouceiro |
| Keywords | socket.io, socket, rest, router |

## Links

- npm: https://www.npmjs.com/package/socket-rest
- Repository: https://github.com/fcouceiro/socket-rest
- Homepage: https://github.com/fcouceiro/socket-rest#readme
- Issues: https://github.com/fcouceiro/socket-rest/issues
- npm.io page: https://npm.io/package/socket-rest

## Dependencies (3)

- [debug](https://npm.io/package/debug.md) ^3.0.1
- [url-parse](https://npm.io/package/url-parse.md) ^1.1.9
- [url-pattern](https://npm.io/package/url-pattern.md) ^1.0.3

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 0.1.2 (latest) — 2017-11-20
- 0.1.1 — 2017-09-15
- 0.1.0 — 2017-09-15

## 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 expressions

The 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.

---
_Source: https://npm.io/package/socket-rest · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
