DEPRECATED! Move to MONOREPO https://github.com/unger1984/di
Router middleware for Dia.
This package allows you to create separate middleware for specific urls and http methods
Add to pubspec.yaml in dependencies section this:
dia_router: ^0.1.6
Then run pub get
A simple usage example:
import 'dart:io';
import 'package:dia/dia.dart';
import 'package:dia_router/dia_router.dart';
/// Custom Context with Routing mixin
class ContextWithRouting extends Context with Routing {
ContextWithRouting(HttpRequest request) : super(request);
}
main() {
final app = App((req)=>ContextWithRouting(req));
final router = Router('/prefix');
router.get('/path/:id', (ctx,next) async {
ctx.body = 'params=${ctx.parsms} query=${ctx.query}';
});
app.use(router.middleware);
app
.listen('localhost', 8080)
.then((info) => print('Route example on http://localhost:8080/perfix/path/12?count=10'));
}
GET http://localhost:8080/perfix/path/12?count=10
params={id:12} query={count:10}
Router support all HTTP method: GET,POST,PUT,PATCH,OPTION,DELETE,HEADER,CONNECT,TRACE
For more details, please, see example folder and test folder.
- dia - A simple dart http server in Koa2 style.
- dia_cors - Package for CORS middleware.
- dia_body - Package with the middleware for parse request body.
- dia_static - Package to serving static files.
change
final app = App<ContextWithRouting>();
to
final app = App((req)=>ContextWithRouting(req));
I will be glad for any help and feedback! Please file feature requests and bugs at the issue tracker.