call method

Future<Response> call(
  1. Request request
)

Route incoming requests to registered handlers.

This method allows a Router instance to be a Handler.

Implementation

Future<Response> call(Request request) async {
  // Note: this is a great place to optimize the implementation by building
  //       a trie for faster matching... left as an exercise for the reader :)
  for (var route in _routes) {
    if (route.verb != request.method.toUpperCase() && route.verb != 'ALL') {
      continue;
    }
    var params = route.match('/${request.url.path}');
    if (params != null) {
      final response = await route.invoke(request, params);
      if (response != routeNotFound) {
        return response;
      }
    }
  }
  return _notFoundHandler(request);
}