addRoute method

APIModule addRoute(
  1. APIRequestMethod? method,
  2. String name,
  3. APIRouteFunction function, {
  4. Map<String, TypeInfo>? parameters,
  5. Iterable<APIRouteRule>? rules,
  6. APIRouteConfig? config,
})

Adds a route, of name, to this module.

method The route method. If null accepts any method. function The route handler, to process calls.

Implementation

APIModule addRoute(
    APIRequestMethod? method, String name, APIRouteFunction function,
    {Map<String, TypeInfo>? parameters,
    Iterable<APIRouteRule>? rules,
    APIRouteConfig? config}) {
  if (method == APIRequestMethod.OPTIONS) {
    throw ArgumentError("Can't add a route with method `OPTIONS`."
        "Requests with method `OPTIONS` are reserved for CORS or other informational requests.");
  }

  var routesHandlers = _getRoutesHandlers(method);
  routesHandlers[name] = APIRouteHandler(
      this, method, name, function, parameters, rules, config);
  return this;
}