addRoute method
APIModule
addRoute(
- APIRequestMethod? method,
- String name,
- APIRouteFunction function, {
- Map<
String, TypeInfo> ? parameters, - Iterable<
APIRouteRule> ? rules, - 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;
}