on<T, B> method
- @mustCallSuper
- Route route,
- Future<
T> handler(- RequestContext<
B> context
- RequestContext<
- bool shouldValidateMultipart = false,
inherited
The on method is used to register a route.
It takes a Route and a ReqResHandler.
It should not be overridden.
Implementation
@mustCallSuper
void on<T, B>(
Route route,
Future<T> Function(RequestContext<B> context) handler, {
bool shouldValidateMultipart = false,
}) {
final routeExists = _routes.values.any(
(r) => r.route.path == route.path && r.route.method == route.method,
);
if (routeExists) {
throw StateError(
'A route with the same path and method already exists. [${route.path}] [${route.method}]',
);
}
_routes[UuidV4().generate()] = RestRouteHandlerSpec<T, B>(
route,
ReqResHandler<T, B>(handler),
shouldValidateMultipart: shouldValidateMultipart,
);
}