onStatic<T> method

  1. @mustCallSuper
void onStatic<T>(
  1. Route route,
  2. T handler
)
inherited

The onStatic method is used to register a static route. It takes a Route and a Object value.

It should not be overridden.

Implementation

@mustCallSuper
void onStatic<T>(Route route, T handler) {
  if (handler is Function) {
    throw StateError('The handler must be a static value');
  }
  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, dynamic>(
    route,
    ReqResHandler<T, dynamic>((_) async => handler),
    shouldValidateMultipart: false,
    isStatic: true,
  );
}