on<T, B> method

  1. @mustCallSuper
void on<T, B>(
  1. Route route,
  2. Future<T> handler(
    1. RequestContext<B> context
    ), {
  3. 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,
  );
}