Modules@robinpath/router

@robinpath/router

0.1.0Public

URL routing and pattern matching with support for path parameters (:param), wildcards (*), route groups, and middleware. No external dependencies.

@robinpath/router

URL routing and pattern matching with support for path parameters (:param), wildcards (*), route groups, and middleware. No external dependencies.

Category Functions Auth License

Why use this module?

The router module lets you:

  • Create a new router instance
  • Add a route with method, path pattern, and handler
  • Match a URL against registered routes and return the matching route
  • Extract path parameters from a URL using a pattern
  • Parse a URL into pathname, segments, and query parameters

All functions are callable directly from RobinPath scripts with a simple, consistent API.

Installation

npm install @robinpath/router

Quick Start

No credentials needed — start using it right away:

router.add

Available Functions

FunctionDescription
router.createCreate a new router instance
router.addAdd a route with method, path pattern, and handler
router.matchMatch a URL against registered routes and return the matching route
router.paramsExtract path parameters from a URL using a pattern
router.parseParse a URL into pathname, segments, and query parameters
router.buildBuild a URL from a pattern and parameter values
router.normalizeNormalize a URL path (collapse slashes, ensure leading slash, strip trailing slash)
router.isMatchTest if a URL path matches a route pattern
router.groupCreate a route group with a shared prefix
router.listList all routes registered in a router
router.removeRemove routes by method and/or path
router.middlewareAdd a middleware function to the router

Examples

Add a route with method, path pattern, and handler

router.add

Match a URL against registered routes and return the matching route

router.match

Extract path parameters from a URL using a pattern

router.params

Integration with RobinPath

import { RobinPath } from "@wiredwp/robinpath";
import Module from "@robinpath/router";

const rp = new RobinPath();
rp.registerModule(Module.name, Module.functions);
rp.registerModuleMeta(Module.name, Module.functionMetadata);

const result = await rp.executeScript(`
  router.add
`);

Full API Reference

See MODULE.md for complete documentation including all parameters, return types, error handling, and advanced examples.

Related Modules

License

MIT

Versions (1)

VersionTagPublished
0.1.0latestyesterday
Install
$ robinpath install @robinpath/router
Version0.1.0
LicenseMIT
Unpacked Size5.9 KB
Versions1
Weekly Downloads0
Total Downloads0
Stars0
Last Publishyesterday
Createdyesterday

Category

web