Controller class

Базовый контроллер для обработки HTTP-запросов.

Этот абстрактный класс предоставляет шаблон для обработки запросов, устанавливая объект Request и вызывая метод handler(), который должен быть реализован в подклассах.

Основные методы

  • call(Request request): Устанавливает текущий запрос и вызывает handler().
  • handler(): Должен быть реализован в подклассах для обработки запроса.
  • requestAsJson(): Читает тело запроса и парсит его как JSON.

Использование

class MyController extends Controller {
  @override
  Future<Response> handler() async {
    final data = await requestAsJson();
    return Response.ok('Received: ${data.toString()}');
  }
}
Implementers

Constructors

Controller()

Properties

endpoint ↔ String
getter/setter pair
hashCode → int
The hash code for this object.
no setterinherited
request ↔ Request
getter/setter pair
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

call(Request request) → FutureOr<Response>
handler() → FutureOr<Response>
Must be implemented
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
requestAsJson() → Future
Reads request value and parse as json
toString() → String
A string representation of this object.
inherited

Operators

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