mirror of
https://github.com/felixblaschke/shelf_plus.git
synced 2025-08-03 17:43:18 +08:00
25 lines
572 B
Dart
25 lines
572 B
Dart
// ignore_for_file: prefer_function_declarations_over_variables
|
|
|
|
import 'package:shelf_plus/shelf_plus.dart';
|
|
|
|
void main() => shelfRun(init);
|
|
|
|
Handler init() {
|
|
var app = Router().plus;
|
|
// #begin
|
|
// define custom ResponseHandler
|
|
ResponseHandler catResponseHandler = (Request request, dynamic maybeCat) =>
|
|
maybeCat is Cat ? maybeCat.interact() : null;
|
|
|
|
// register custom ResponseHandler as middleware
|
|
app.use(catResponseHandler.middleware);
|
|
|
|
app.get('/cat', () => Cat());
|
|
// #end
|
|
return app.call;
|
|
}
|
|
|
|
class Cat {
|
|
String interact() => 'Purrrrr!';
|
|
}
|