Endpoint class

Annotation for defining API endpoints.

Apply this annotation to a class that extends SparkEndpoint.

Usage

@Endpoint(path: '/api/users/{id}', method: 'GET')
class GetUserEndpoint extends SparkEndpoint<void> {
  @override
  Future<UserDto> handler(SparkRequest request, void body) async {
    final userId = request.pathParamInt('id');
    return await userService.getUser(userId);
  }
}

With Middleware

@Endpoint(path: '/api/admin/users', method: 'GET')
class AdminUsersEndpoint extends SparkEndpoint<void> {
  @override
  List<Middleware> get middleware => [
    authMiddleware(authService),
  ];

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

Constructors

Endpoint({required String path, required String method, String? summary, String? description, List<String>? tags, bool? deprecated, List<Map<String, List<String>>>? security, String? operationId, ExternalDocumentation? externalDocs, List<Parameter>? parameters, List<String>? contentTypes, int? statusCode})
Creates an endpoint annotation.
const

Properties

contentTypes → List<String>?
A list of supported content types for this endpoint.
final
deprecated → bool?
Declares this operation to be deprecated.
final
description → String?
A verbose explanation of the operation behavior.
final
externalDocs → ExternalDocumentation?
Additional external documentation for this operation.
final
hashCode → int
The hash code for this object.
no setterinherited
method → String
The HTTP method for this endpoint (e.g., 'GET', 'POST').
final
operationId → String?
Unique string used to identify the operation.
final
parameters → List<Parameter>?
A list of parameters that are applicable for this operation.
final
path → String
The URL path for this endpoint (e.g., '/api/users/{id}').
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
security → List<Map<String, List<String>>>?
A declaration of which security mechanisms can be used for this operation.
final
statusCode → int?
The default status code for the successful response (e.g., 200, 201).
final
summary → String?
A short summary of what the operation does.
final
tags → List<String>?
A list of tags for API documentation control.
final

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