makeList static method

List<FinchRoute> makeList({
  1. required List<String> paths,
  2. List<String> extraPath = const [],
  3. List<String> methods = const [Methods.GET],
  4. Controller? controller,
  5. Future<String> index()?,
  6. AuthController? auth,
  7. List<String> permissions = const [],
  8. String widget = "",
  9. Map<String, Object?> params = const {},
  10. String title = "",
  11. List<String> excludePaths = const [],
  12. List<FinchRoute> children = const [],
  13. Future<ApiDoc>? apiDoc()?,
  14. List<String> hosts = const ['*'],
  15. List<int> ports = const [],
  16. String? key,
})

Creates multiple FinchRoute instances with shared configuration.

This factory method simplifies the creation of multiple routes that share the same configuration (methods, controller, authentication, etc.) but have different paths. It's particularly useful for creating route groups or when you need similar routes for different endpoints.

All parameters except paths are optional and will be applied to all created routes. Each path in the paths list will generate a separate FinchRoute instance with the shared configuration.

paths List of path patterns for which to create routes extraPath Additional path aliases for each route methods HTTP methods allowed for all routes (defaults to GET) controller Controller instance to handle requests for all routes index Function to handle index requests for all routes auth Authentication controller for all routes permissions Required permissions for all routes widget Widget/template path for all routes params Default parameters for all routes title Page title for all routes excludePaths Paths to exclude from wildcard matching children Child routes for all routes apiDoc API documentation generator function hosts Host restrictions for all routes ports Port restrictions for all routes

Returns a list of configured FinchRoute instances.

Example:

final userRoutes = WebRoute.makeList(
  paths: ['/users', '/members', '/people'],
  methods: [RequestMethods.GET, RequestMethods.POST],
  controller: UserController(),
  auth: UserAuthController(),
  permissions: ['user.read'],
);

Implementation

static List<FinchRoute> makeList({
  required List<String> paths,
  List<String> extraPath = const [],
  List<String> methods = const [Methods.GET],
  Controller? controller,
  Future<String> Function()? 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>? Function()? apiDoc,
  List<String> hosts = const ['*'],
  List<int> ports = const [],
  String? key,
}) {
  var res = <FinchRoute>[];

  int i = 0;
  for (var path in paths) {
    i++;
    final route = FinchRoute(
      path: path,
      index: index,
      apiDoc: apiDoc,
      auth: auth,
      children: children,
      controller: controller,
      excludePaths: excludePaths,
      extraPath: extraPath,
      methods: methods,
      params: params,
      permissions: permissions,
      title: title,
      widget: widget,
      hosts: hosts,
      ports: ports,
      key: key != null ? '$key.$i' : null,
    );
    res.add(route);
  }

  return res;
}