Skip to content

Universal router for modern JavaScript and TypeScript apps. Works seamlessly across Node.js and browser environments. Built for serverless, SSR, and SPA with a functional, composable API.

License

Notifications You must be signed in to change notification settings

stone-foundation/stone-js-router

Repository files navigation

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

About

Universal router for modern JavaScript and TypeScript apps. Works seamlessly across Node.js and browser environments. Built for serverless, SSR, and SPA with a functional, composable API.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks