Skip to content

RestNio/RestNio.js

Repository files navigation

RestNio

RestNio.js

One routing model for HTTP and WebSocket. Bimodal routes, built-in validation, JWT auth, and shipped TypeScript types — in one small Node package.

npm node types license

restn.io  ·  Documentation Wiki  ·  npm


Install

npm install restnio

Hello, RestNio

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

What's in the box

  • 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)
  • Pluginsserve(), cors(), ratelimit() mount as route middleware
  • Binary WS routing — named binary routes and codec negotiation (JSON + MessagePack)
  • Outbound connectorsRestNio.request, RestNio.http, RestNio.websocket
  • Interconnect — persistent peer links between RestNio servers, with reusable route definitions
  • TypeScript — ships .d.ts with path-param type inference

Documentation

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

Scripts

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 JSDoc

License

MIT © 7kasper

About

RestNio implementation for Node.js

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors