route_provider 4.2.3 route_provider: ^4.2.3 copied to clipboard
Provides backend routing for http-servers. Split routes into separates parts: authentification, controller for data processing and response for outputting the results.
dart-routeprovider #
Installation #
Add it to your dependencies
dependencies:
route_provider: ^4.2.3
and install the package
$ pub get
Usage #
import 'dart:io';
import 'package:route_provider/route_provider.dart';
main() {
Auth freeForAll = StaticAuth(authed: true);
Auth userAuth = MyAuth();
Responser jsonResponser = JsonResponse();
HttpServer.bind(InternetAddress.anyIPv4,8080).then((HttpServer server){
Router(server)
..route(
url: "/",
responser: FileResponse("docroot/index.html"),
auth: freeForAll
)
..route(
url: '/assets/**',
responser: FolderResponse("docroot/assets/"),
auth: freeForAll
)
..route(
url: "/impress",
responser: FileResponse("docroot/impress.html"),
auth: freeForAll
)
..route(
url: "/api/data/:id",
controller: DataRestApiController(),
responser: jsonResponser,
auth: userAuth
)
..start();
}).catchError((e) => print(e.toString()));
}
Contributing #
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request
Credits #
Robert Beyer 4sternrb@googlemail.com
License #
MIT