http_router 0.1.0
http_router: ^0.1.0 copied to clipboard
A simple http router
example/main.dart
import 'dart:io';
import 'dart:async';
import 'package:http_router/http_router.dart';
import './handlers/index.dart';
import './handlers/missing.dart';
main() {
// bind the server to a host and port
Future<HttpServer> server = HttpServer.bind("127.0.0.1", 3000);
// whenever the server finishes binding
server.then((HttpServer server) {
// Initialize the router with specified vhosts and routes
var httpRouter = new HttpRouter({
'r:.*:3000': {
'GET': {
'/': new IndexHandler()
}
}
}, new FallbackHandler());
// pipe http requests to the http router
server.pipe(httpRouter);
});
}