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 methods
- RequestMethods.ONLY_GET- Only GET requests
- RequestMethods.ONLY_POST- Only POST requests
- RequestMethods.ONLY_PUT- Only PUT requests
- RequestMethods.ONLY_DELETE- Only DELETE requests
- RequestMethods.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