handlerRoute method

Route? handlerRoute(
  1. RequestEntity request
)

Return the route that will handle the request If a null value is returned, it means that this router can handle the request with a route It will return an status code like 404 or 415

Implementation

Route? handlerRoute(RequestEntity request) {
  ///find routes that match with the path
  String urlPath = '/${request.url.path}';
  List<Route> matchedRoutes = routes
      .where(
        (element) => element.match(urlPath),
      )
      .toList();

  ///no routes found: 404
  if (matchedRoutes.isEmpty) {
    return null;
  } else {
    ///there is some route, check method (get, post, put...)
    return matchedRoutes.firstWhereOrNull(
      (element) => element.method == HttpMethod(request.method),
    );
  }
}