@stone-js/router
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

Stone.js - Router

npm npm npm Maintenance Build Status Publish Package to npmjs Quality Gate Status Coverage Security Policy CodeQL Dependabot Status Conventional Commits

Stone.js router for both Node.js and browser environments, designed for serverless applications.


Overview

Stone Router is a high-performance, universal router designed to work seamlessly across Node.js and browser environments. As a core part of the Stone.js framework, it enables robust, declarative, and composable route handling for serverless, SSR, and SPA applications.

Key Features

  • Universal: Works on both backend and frontend (Node.js, browsers, SSR apps).
  • Composable: Supports route builders, chaining, and nested route structures.
  • Context-Aware: Routes are designed to respond to the execution context.
  • Type-Safe & Declarative: Built with TypeScript-first principles.
  • Fast & Lightweight: Optimized for high-performance and minimal overhead.
  • Model Binding: Automatically inject models and bindings into routes.
  • Flexible Middleware System: Apply middleware globally or per route.
  • Regex and Dynamic Params: Advanced matching for custom use cases.
  • Error Handling & Fallbacks: Integrated with the event lifecycle.
  • Smart Defaults: Supports defaults, route rules, redirect handling, etc.

Installation

npm install @stone-js/router

[!IMPORTANT] This package is pure ESM. Ensure your package.json includes "type": "module" or configure your bundler appropriately.

Usage

Stone Router exposes a functional/declarative API that allows defining, composing, and dispatching routes easily. It is designed to be used in both server and client contexts, making it ideal for modern web applications that require a unified routing solution. It fully integrates with the event system of Stone.js through IncomingEvent and OutgoingResponse.

import { IncomingEvent } from '@stone-js/core'
import { defineRoutes } from '@stone-js/router'

export const routes = defineRoutes([
  {
    method: 'GET',
    path: '/users/:id',
    handler: async (event: IncomingEvent) => {
      return { body: `User ID: ${event.get('id') }` }
    }
  }
])

Learn More

This package is part of the Stone.js ecosystem, a modern JavaScript framework built around the Continuum Architecture.

Explore the full documentation: https://stonejs.dev

API documentation

Contributing

See Contributing Guide

Package Sidebar

Install

npm i @stone-js/router

Homepage

stonejs.dev

Weekly Downloads

15

Version

0.1.0

License

MIT

Unpacked Size

192 kB

Total Files

5

Last publish

Collaborators

  • stone509