One routing model for HTTP and WebSocket. Bimodal routes, built-in validation, JWT auth, and shipped TypeScript types — in one small Node package.
npm install restnioconst RestNio = require('restnio');
const app = new RestNio((router, rnio) => {
router.get('/', () => 'Hello from RestNio');
router.post('/dog/:name/feed', {
permissions: ['dog.feed.:name'],
params: {
portion: rnio.params.integer
},
func: (params) => ({ fed: params.name, amount: params.portion })
});
router.ws('/chat', (params, client) => {
rnio.subs(params.room).obj({ from: client.state.name, text: params.text });
});
}, { port: 7070 });
app.bind();Same route, both protocols. The POST above works over curl and over a WebSocket envelope { "path": "/dog/fido/feed", "params": { "portion": 2 } } — no extra wiring.
- Bimodal routing — HTTP and WebSocket share route definitions by default
- Param validation — type coercion, shorthand helpers, checks and formatters in one pass
- JWT auth — per-route permissions with path-param substitution (
dog.feed.:name) - Plugins —
serve(),cors(),ratelimit()mount as route middleware - Binary WS routing — named binary routes and codec negotiation (JSON + MessagePack)
- Outbound connectors —
RestNio.request,RestNio.http,RestNio.websocket - Interconnect — persistent peer links between RestNio servers, with reusable route definitions
- TypeScript — ships
.d.tswith path-param type inference
The full guide lives in the GitHub Wiki:
| Quick Start | Smallest working server |
| Routing | Bimodal, HTTP-only, WS-only, path params, nesting |
| Params & Validation | Types, checks, formatters, shorthands |
| Auth & Permissions | JWT tokens, cookie auth, permission templates |
| WebSocket | Routing, subscriptions, broadcasting |
| Binary Routing | Upload pattern, named binary routes |
| Codecs | JSON and MessagePack negotiation |
| Plugins | Static serving, CORS, rate limiting |
| Connectors | Outbound HTTP + WebSocket clients |
| Interconnect | Persistent server-to-server peer links |
| TypeScript | Declarations and inference |
| Operations | Proxy config, security checklist |
npm test # all tests
npm run test:unit # unit tests
npm run test:integration # integration tests
npm run test:e2e # end-to-end
npm run test:coverage # coverage (80% lines/stmts/branches/fns)
npm run test:types # typecheck .d.ts
npm run build:types # regenerate .d.ts from JSDocMIT © 7kasper
