FinchRoute class

Defines a web route configuration for HTTP request handling in the application. The FinchRoute class represents a single route definition that specifies how incoming HTTP requests should be matched and handled. It supports advanced routing features including pattern matching, HTTP method filtering, host/port restrictions, nested routing, authentication, and authorization. Key features:

  • Path pattern matching with wildcards (/api/*) and parameters (/users/{id})
  • HTTP method restrictions (GET, POST, PUT, DELETE, etc.)
  • Host and port-based routing for multi-tenant applications
  • Nested route hierarchies for organized route structures
  • Integration with authentication and authorization systems
  • Controller-based and function-based request handling
  • Widget/template rendering capabilities
  • API documentation generation support Example usage:
// Simple route
WebRoute(
  path: '/users',
  methods: [RequestMethods.GET],
  index: () async => 'User list',
)
// Parameterized route with authentication
WebRoute(
  path: '/users/{id}',
  methods: [RequestMethods.GET, RequestMethods.PUT],
  auth: UserAuthController(),
  permissions: ['user.read', 'user.edit'],
  controller: UserController(),
)
// Nested route structure
WebRoute(
  path: '/api',
  children: [
    WebRoute(path: '/users', controller: UserApiController()),
    WebRoute(path: '/posts', controller: PostApiController()),
  ],
)

Constructors

FinchRoute({required String path, String? key, List<String> extraPath = const [], List<String> methods = const [Methods.GET], Controller? controller, String widget = "", Future<String> index()?, AuthController? auth, List<FinchRoute> children = const [], Map<String, Object?> params = const {}, String title = '', List<String> excludePaths = const [], Future<ApiDoc>? apiDoc()?, List<String> permissions = const [], List<String> hosts = const ['*'], List<int> ports = const []})
Creates a FinchRoute instance with the specified parameters.

Properties

apiDoc Future<ApiDoc>? Function()?
Function to generate API documentation for this route.
getter/setter pair
auth AuthController?
An optional AuthController for handling authentication and session checks for this route.
getter/setter pair
children List<FinchRoute>
Sub-routes of the current route, defining a tree structure of routes.
getter/setter pair
controller Controller?
The controller associated with this route. This is an instance of Controller that will handle the request for this route.
getter/setter pair
excludePaths List<String>
Paths that should not be included in all sub-paths of /*.
getter/setter pair
extraPath List<String>
Additional main paths for this route. This allows for multiple matching paths.
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
hosts List<String>
The primary hostname constraints for this route.
getter/setter pair
index Future<String> Function()?
A function representing the main controller function to load for this route. This is typically used to render the index of the controller.
getter/setter pair
key String?
Key of routes of the current route, defining a tree structure of routes.
getter/setter pair
methods List<String>
List of HTTP methods allowed for this route. For example, POST, GET, HEAD, etc.
getter/setter pair
params Map<String, Object?>
Default variable parameters to use in the content.
getter/setter pair
parent FinchRoute?
getter/setter pair
path String
The primary path of the route. For example, /test or /test/*. If using /test/*, it will match all sub-paths under /test.
getter/setter pair
permissions List<String>
Permissions required for this route. Authentication is needed to use these permissions.
getter/setter pair
ports List<int>
The port number constraints for this route.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
title String
The title of the page, which can be used as {{ $e.pageTitle }}.
getter/setter pair
widget String
Path to the widget to be loaded as content for this route.
getter/setter pair

Methods

allowMethod() bool
Validates if the current HTTP request method is allowed for this route.
getFullPath() String
getPathRender() String
Gets the path after rendering.
getUrl([Map<String, Object?> params = const {}, Map<String, Object?> queries = const {}]) String
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
setPathRender(String path) → void
Sets the rendered path for this route.
toDetails() Map<String, Object?>
toMap(String parentPath, bool hasAuth, String method) List<Map>
Converts the route to a list of maps representing its details.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

getByKey(String key) FinchRoute?
getPath(String key) String
makeList({required List<String> paths, List<String> extraPath = const [], List<String> methods = const [Methods.GET], Controller? controller, Future<String> index()?, AuthController? auth, List<String> permissions = const [], String widget = "", Map<String, Object?> params = const {}, String title = "", List<String> excludePaths = const [], List<FinchRoute> children = const [], Future<ApiDoc>? apiDoc()?, List<String> hosts = const ['*'], List<int> ports = const [], String? key}) List<FinchRoute>
Creates multiple FinchRoute instances with shared configuration.