Controller class abstract

Controller defines the interface all Jaguar controllers must implement.

before method is called before any route handler belonging to the controller is called.

Use GenController annotation to tell Jaguar that your controller class is a controller.

Implement route handlers as methods in your controller class and annotate them with one of the HttpMethod annotations.

import 'dart:async';
import 'package:jaguar/jaguar.dart';
import 'package:jaguar_reflect/jaguar_reflect.dart';
@GenController(path: '/library')
class LibraryApi extends Controller {
  @Get(path: '/all')
  Future<List<Book>> getAll(Context ctx) => books;

  @Post(path: '/add')
  Future<void> add(Context ctx) {
    // TODO
  }
}

main(List<String> args) async {
  final server = Jaguar(port: 10000);
  server.add(reflect(LibraryApi()));
  await server.serve();
}

Constructors

Controller()
const

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

before(Context ctx) FutureOr<void>
Called before a route handler is invoked
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