on<T> method

MethodRouter on<T>(
  1. String method,
  2. Endpoint<T> endpoint, {
  3. int status = 200,
})

Returns a set with endpoint added for method.

Each step returns a new value rather than mutating, so a half-built chain cannot be aliased into two routes. status is the success status, which is how a create says 201; a failure keeps its own.

Implementation

MethodRouter on<T>(String method, Endpoint<T> endpoint, {int status = 200}) {
  final verb =
      method == Route.anyMethod ? Route.anyMethod : method.toUpperCase();
  if (handlers.containsKey(verb)) {
    throw ArgumentError('$verb is already registered for this path');
  }
  return MethodRouter._(
    Map.unmodifiable({...handlers, verb: _adapt(endpoint, status)}),
  );
}