dartness 0.0.18 copy "dartness: ^0.0.18" to clipboard
dartness: ^0.0.18 copied to clipboard

outdated

micro framework for dart based on middleware. Made for rest api.

Dartness

minimalist middleware based web framework

import 'package:dartness/dartness.dart';

void main() {

  final app = new Dartness();
  final router = new Router();
  
  router.get('/', (Context context) async => null);
  
  app.use(router);
  
  app.listen(port: 4040);

}
  • uses middleware to create working flow
  • simple

Basic features:

  • all parts is middleware
  • errors can be captured on any step
  • can be used simple dynamic routes
  • router skips followed routes, if one was matched
  • middleware can be grouped into modules

Roadmap:

  • add regexp routes
  • add logger
  • add nester routes
  • add middleware chains

Full Example:

import 'package:dartness/dartness.dart';
  
void main() {
 
  final app = new Dartness();
  
  app.use((Context context) async {
    // will be called first
  }, catchError: false);
  
  app.use((Context context) async {
    // will be called second
    // catchError = false by dedault
    throw new Error(); // will be called first middleware with catchError = true 
  });
  
  final router = new Router();
  
  router.get('/:param1/:param2/:param3', (Context context) async {
    // context.req.params = {'param1': 'value', 'param2': 'value2', 'param3': 'value3'}
    print (context.req.params.toString());
  }); 
  
  // simple ger request
  router.get('/', (Context context) async => null);
    
  // simple post request
  // uses body_parser to decode:
  // application/json 
  // application/x-www-form-urlencoded
  // multipart/form-data
  router.post('/', (Context context) async => print(context.req.body['message']['text']));
 
  app.use(router); // you can use more than one router
 
  app.use((Context context) async {
    // will be called only if error will be thrown
  }, catchError: true);
  
  app.listen(port: 4040);
}
0
likes
0
pub points
34%
popularity

Publisher

unverified uploader

micro framework for dart based on middleware. Made for rest api.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

body_parser

More

Packages that depend on dartness