Routing
Advanced routing with authentication, permissions, and dynamic paths
Routing in WebApp Package
WebApp provides a powerful and flexible routing system with built-in support for authentication, permissions, nested routes, and dynamic path handling.
Basic Routing Structure
The getWebRoute
function returns a list of routes that define how your application handles incoming requests:
Route Features
1. Request Methods
Control which HTTP methods a route accepts:
2. Authentication and Authorization
Protect routes with authentication and permissions:
3. Host and Port Restrictions
Restrict routes to specific hosts and ports:
4. Dynamic Paths and Wildcards
Handle dynamic paths with wildcards:
5. Nested Routes
Organize routes hierarchically:
6. Controllers
Associate entire controllers with routes:
Route Parameters
Access route parameters in your controllers:
Redirects
Perform redirects within routes:
Request Methods Enum
Available request method options:
RequestMethods.ALL
- Accept all HTTP methodsRequestMethods.ONLY_GET
- Only GET requestsRequestMethods.ONLY_POST
- Only POST requestsRequestMethods.ONLY_PUT
- Only PUT requestsRequestMethods.ONLY_DELETE
- Only DELETE requestsRequestMethods.ONLY_PATCH
- Only PATCH requests
Best Practices
- Organize by Feature: Group related routes under common parent paths
- Use Controllers: Leverage controllers for organized code structure
- Secure Sensitive Routes: Always add authentication for protected areas
- Validate Permissions: Use granular permissions for role-based access
- Handle Errors: Implement proper error handling in route handlers
- Document Routes: Keep route documentation up to date
Next Steps
- Learn about Controllers for handling route logic
- Explore Authentication for securing routes
- Check out Middleware for request processing