SparkEndpointWithBody<T> class
abstract
Abstract base class for Spark API endpoints with a typed request body.
Use this for POST, PUT, PATCH, or other endpoints that expect a body.
The generic type T represents the request body type that will be
automatically parsed from JSON.
Basic Usage
@Endpoint(path: '/api/users', method: 'POST')
class CreateUserEndpoint extends SparkEndpointWithBody<CreateUserDto> {
@override
Future<UserDto> handler(SparkRequest request, CreateUserDto body) async {
final user = await userService.create(body);
return user;
}
}
With Middleware
@Endpoint(path: '/api/admin/users', method: 'POST')
class AdminCreateUserEndpoint extends SparkEndpointWithBody<CreateUserDto> {
final AuthService _authService;
AdminCreateUserEndpoint(this._authService);
@override
List<Middleware> get middleware => [
authMiddleware(_authService),
];
@override
Future<UserDto> handler(SparkRequest request, CreateUserDto body) async {
return await userService.create(body);
}
}
Constructors
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, T body) → Future - Handles incoming requests with a parsed body.
-
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