-
Notifications
You must be signed in to change notification settings - Fork 35
Controllers
Controllers are declarative way to write route handlers in Jaguar (as an alternative to mux-based routing). Each route handler is implemented as a method in the Controller class. The route handlers shall be annotated with one of the HTTP method annotations for Jaguar to recognize them. The controller class itself shall be annotated with GenController
.
@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
}
}
Controller
class's before
method is called before any of the route handlers in the controller is executed. Here, you can directly execute other interceptors, register interceptors to be executed before or after the route handler execution using before
and after
methods of Context
class.
@GenController(path: '/library')
class LibraryApi extends Controller {
@Get(path: '/all')
Future<List<Book>> getAll(Context ctx) => books;
Future<void> before(Context ctx) async {
await mongoPool(ctx);
await Authorizer.authorize(ctx);
ctx.after((_) => print("After"));
}
}
Reflected easier of the two methods to add Controllers to Jaguar server, so it is best to use when you are getting started with Jaguar.
jaguar_reflect
package provides reflect
method which can be used to compile Route
specs from your controller class. The returned Route specs can be added to Jaguar server using the add
method.
import 'package:jaguar_reflect/jaguar_reflect';
main() async {
final server = Jaguar();
server.add(reflect(LibraryApi()));
}
TODO
Basics
- Route handler
- Path matching
- Path parameters
- Query parameters
- Serving static files
- Cookies
- Controller
- Parameter binding
- Hot reload
Serialization
Forms
Sessions
Authentication
- Basic authentication
- Form authentication
- JSON authentication
- Authorization
- OAuth
- MongoDb
- PostgreSQL
- MySQL
- Establish connection
- ORM
- Server sent events (SSE)
- Websockets
- systemd
- Docker
- AppEngine