handle method

Future<ServerResponse>? handle(
  1. HttpMethod method,
  2. RequestContext request,
  3. RouteMatches matches
)

Runs the handler for method, or returns null when none exists.

Implementation

Future<ServerResponse>? handle(
  HttpMethod method,
  RequestContext request,
  RouteMatches matches,
) {
  final handler =
      handlers[method] ??
      (method == HttpMethod.head ? handlers[HttpMethod.get] : null);
  if (handler == null) return null;
  final match = matches.match(this)!;
  return Future<ServerResponse>.sync(
    () => handler(
      ServerRouteContext<P, S>(
        context: request,
        params: match.params,
        search: match.search,
        location: match.location,
      ),
    ),
  );
}