dia_router 0.1.7 copy "dia_router: ^0.1.7" to clipboard
dia_router: ^0.1.7 copied to clipboard

A router for Dia. Allow add dia middlewares for handle different url addresses.

Pub Package

Router middleware for Dia.

This package allows you to create separate middleware for specific urls and http methods

Install: #

Add to pubspec.yaml in dependencies section this:

    dia_router: ^0.1.7

Then run pub get

Usage: #

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.

Use with: #

  • 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.

Migration from 0.0.* #

change

final app = App<ContextWithRouting>();

to

final app = App((req)=>ContextWithRouting(req));

Features and bugs: #

I will be glad for any help and feedback! Please file feature requests and bugs at the issue tracker.

1
likes
160
pub points
60%
popularity

Publisher

verified publisherawcoding.com

A router for Dia. Allow add dia middlewares for handle different url addresses.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

dia, path_to_regexp

More

Packages that depend on dia_router