Intelligent Routing
Routes that optimize themselves. Middleware ordered automatically. Type safety built-in. No manual configuration needed.
On this page
Routing That Thinks for You
Define your routes. We handle the optimization.
Middleware ordering, route compilation, and type safety—all automatic.
Simple Route Definition
Define routes - everything else is automatic
typescript
Why Intelligent Routing Matters
Traditional frameworks make you manually order middleware and optimize routes. We do that automatically.
Without intelligent routing, you're manually ordering middleware, optimizing execution paths, and managing route compilation.
Traditional Frameworks
- •Manual middleware ordering
- •Route compilation at runtime
- •No automatic optimization
- •Type safety requires extra work
With MoroJS
- •Automatic middleware ordering
- •Routes compiled at startup
- •Optimized execution paths
- •Type safety built-in
It's This Easy
Define your route. Add middleware. We handle the rest.
Chainable API - Recommended
typescript
Why It Makes Sense
Automatic Optimization
Middleware ordered optimally. Routes compiled at startup. Maximum performance.
Type Safe
Parameters, query strings, and bodies are automatically typed. No manual type definitions.
Smart Middleware
Middleware runs in the right order automatically. No manual configuration needed.
How It Works
MoroJS analyzes your routes at startup and creates an optimized execution plan. Middleware is automatically ordered based on dependencies, routes are compiled for maximum performance, and types are inferred from your route patterns and schemas.
Basic Route Definition
typescript
Advanced Route Configuration
typescript
Route Patterns
MoroJS supports a variety of route patterns, from simple static routes to complex parameterized paths.
Supported Route Patterns
typescript
Intelligent Middleware System
Middleware runs in an optimal order automatically. Authentication before authorization, validation early, caching optimally placed—all handled for you.
Middleware with Automatic Ordering
typescript
Automatic Ordering
- 1Request parsing
- 2Authentication
- 3Authorization
- 4Validation
- 5Rate limiting
- 6Caching
- 7Handler execution
Performance Benefits
- No manual ordering needed
- Optimal execution path
- Early exit on failures
- Compile-time optimization
- Type-safe context passing
Route Compilation & Performance
At application startup, MoroJS analyzes all your routes and creates an optimized execution plan. Routes are compiled, middleware chains are optimized, and type-safe handlers are generated.
Route Compilation Process
- Builds optimal middleware chains
- Pre-compiles route matchers
- Generates type-safe handlers
- Optimizes for common patterns
Route Compilation Example
typescript
Best Practices
Do
- • Use descriptive route patterns
- • Define validation schemas
- • Group related routes together
- • Leverage automatic middleware ordering
- • Use type-safe parameter extraction
- • Define response schemas for documentation
Don't
- • Manually order middleware unnecessarily
- • Skip input validation
- • Use overly complex route patterns
- • Ignore TypeScript warnings
- • Mix business logic in middleware
- • Forget to handle errors properly