add method

void add(
  1. String method,
  2. String route,
  3. Function handler, {
  4. Middleware? middleware,
})

Implementation

void add(String method, String route, Function handler,{Middleware? middleware}) {
  if (!isHttpMethod(method)) {
    throw ArgumentError.value(
        method, 'method', 'expected a valid HTTP method');
  }

  if (route.isEmpty || !route.startsWith('/')) {
    throw ArgumentError.value(
        method, 'route', 'path must begin with "/" in path "$route"');
  }
  method = method.toUpperCase();

  if (method == 'GET') {
    // Handling in a 'GET' request without handling a 'HEAD' request is always
    // wrong, thus, we add a default implementation that discards the body.
    _addRoute('HEAD', route, handler, middleware: _removeBody);
  }
  _addRoute(method, route, handler,middleware:middleware);
}