SparkEndpoint class abstract

Abstract base class for Spark API endpoints without a request body.

Use this for GET, DELETE, or other endpoints that don't expect a body.

Basic Usage

@Endpoint(path: '/api/hello', method: 'GET')
class HelloEndpoint extends SparkEndpoint {
  @override
  Future<String> handler(SparkRequest request) async {
    return 'Hello World';
  }
}

With Middleware

@Endpoint(path: '/api/admin/users', method: 'GET')
class AdminUsersEndpoint extends SparkEndpoint {
  final AuthService _authService;

  AdminUsersEndpoint(this._authService);

  @override
  List<Middleware> get middleware => [
    authMiddleware(_authService),
    adminOnlyMiddleware(),
  ];

  @override
  Future<List<UserDto>> handler(SparkRequest request) async {
    return await userService.getAllUsers();
  }
}

Constructors

SparkEndpoint()

Properties

hashCode int
The hash code for this object.
no setterinherited
middleware List<Middleware>
Middleware to apply to this endpoint's route.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

handler(SparkRequest request) Future
Handles incoming requests.
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