Controller class final

Marks a class as a REST controller in the application.

Controllers handle incoming HTTP requests and define API endpoints. They contain methods annotated with REST annotations (@Get, @Post, etc.) that map to specific HTTP endpoints.

The path parameter defines the base path for all endpoints in the controller.

Example:

@Controller('/api/users')
class UserController {
  final UserService _service;

  UserController(this._service);

  @Get('/')
  Future<Response> getAllUsers(Request request) async {
    final users = await _service.findAll();
    return Response.ok(jsonEncode(users));
  }

  @Get('/:id')
  Future<Response> getUserById(Request request, String id) async {
    final user = await _service.findById(id);
    return user != null
        ? Response.ok(jsonEncode(user))
        : Response.notFound('User not found');
  }
}
Implemented types

Constructors

Controller(String path)
Creates a Controller annotation with the specified base path.
const

Properties

hashCode → int
The hash code for this object.
no setterinherited
path → String
The base path for all endpoints in this controller.
final
registerWithInterfaceOrSuperType → bool
Determines if the component should be registered with its interface or supertype.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited