addAction method

void addAction(
  1. Action action, {
  2. String? path,
  3. ContextProvider? contextProvider,
})

Serves action at POST path, which defaults to '/${action.name}'.

contextProvider builds the action context from the request (typically from auth headers); throwing from it rejects the request.

Paths match exactly, so /hello and /hello/ would be different routes. To avoid that trap, a trailing / is rejected (except for / itself).

Throws an ArgumentError if path doesn't start with /, ends with /, or is already registered on this router.

Implementation

void addAction(
  Action action, {
  String? path,
  ContextProvider? contextProvider,
}) {
  addRoutes(this, [
    (action: action, path: path ?? '/${action.name}'),
  ], contextProvider: contextProvider);
}