Documentation Index
Fetch the complete documentation index at: https://mintlify.com/juanjh1/asimilation/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Asimilation’s routing system provides a flexible way to map URLs to handler functions. It supports both static and dynamic routes with typed parameters, making it easy to build RESTful APIs and web applications.Basic Route Registration
Routes are registered using theaddPath() method on the URL manager. The simplest form accepts a path and a controller function:
The
url object is exported from asimilation/core/main and provides access to the RouteManager instance.Static Routes
Static routes match exact URL paths. These are the most common type of routes:Map structure and provide O(1) lookup performance (see router-manager.ts:45).
Dynamic Routes with Parameters
Dynamic routes allow you to capture parts of the URL as parameters. Asimilation uses a special syntax with angle brackets to define typed parameters:Syntax
typeis the parameter type (int, string, slug, boolean)nameis the parameter name accessible inreq.params
Parameter Types
Asimilation supports four parameter types (defined inenums/param-type.ts:3-6):
Multiple Parameters
You can use multiple parameters in a single route:HTTP Methods
By default, routes respond to all HTTP methods. You can restrict routes to specific methods using themethods option:
Supported HTTP Methods
- GET
- POST
- PUT
- PATCH
- DELETE
- OPTIONS
- HEAD
How Path Matching Works
Parse the URL
The incoming URL is split at the
? to separate the path from query parameters (router-manager.ts:113-115).Check Static Routes
First, Asimilation checks if the path exists in the static routes
Map (router-manager.ts:117).Check Dynamic Routes
If no static match is found, it iterates through registered dynamic route patterns using regex matching (
router-manager.ts:55-60).Extract Parameters
For dynamic routes, named capture groups extract parameter values from the URL (
router-manager.ts:62-72).Validate HTTP Method
The HTTP method is validated against the route’s allowed methods (
router-manager.ts:74-93).Path Normalization
All paths are automatically normalized (defined inhelpers/url-regex.ts:38-47):
- Leading slashes are added if missing
- Multiple consecutive slashes are collapsed
- Trailing slashes are handled consistently
Route Registration Internals
When you calladdPath(), the following happens (see abstract/add_path_abstract.ts:32-51):
- The path is normalized
- The system checks if the path contains typed parameters using
hasTypeParams() - For static paths, the route is added to the
pathsMap - For dynamic paths:
- Parameter names are extracted using
extractParamsNames() - A regex pattern is compiled using
compiledUrlPattern() - The route is added to the
dynamicPathMap with the regex as the key
- Parameter names are extracted using
Example: Building a RESTful API
Performance Characteristics
- Static routes: O(1) lookup time using a Map
- Dynamic routes: O(n) where n is the number of dynamic patterns, but typically very fast for small numbers of routes
- Parameter extraction: O(1) after pattern match using named capture groups
The framework is designed to check static routes before dynamic routes, so frequently accessed static paths have optimal performance.
Next Steps
Middlewares
Learn how to add middleware to your routes
Request & Response
Explore the request and response objects

