dartness 0.0.17

  • readme.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 56

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);
}

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

[Unreleased]

[0.0.17] - 2018-07-05

Added

  • added tests
  • added modules (middleware groups, see example) !!! module's route does not add to included routers

[0.0.16] - 2018-05-24

Added

  • improved examples

Changed

  • Added error to Context

[0.0.15] - 2018-05-23

Added

  • improved example

Changed

  • Formatted code according dart code styles

example/example.dart

import 'dart:io';

import 'package:dartness/dartness.dart';

void main() {

  final app = new Dartness();

  app.use((Context context) async {
    //print('middleware 1');
  }, catchError: false);

  app.use((Context context) async {
    //print('middleware 1.5');
  });

  final router = new Router();

  router.get('/:param1/:param2/:param3', (Context context) async {
    print ('GET /:hello ' + context.req.params.toString());
  });

  router.get('/', (Context context) async => null);
  router.post('/', (Context context) async => print(context.req.body['message']['text']));

  app.use(router);

  app.use((Context context) async {
    // print('sending response');
    context.res..headers.add(HttpHeaders.CONTENT_TYPE, 'application/json')
      ..write('{"qe": "asd", "zxc": 4}')
      ..close();
  });

  app.use((Context context) async {
    print('wow, here is was an error!');
    context.res.write('middleware 2');
  }, catchError: true);

  app.listen(host: InternetAddress.ANY_IP_V4, port: 4040);

}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  dartness: ^0.0.17

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:dartness/dartness.dart';
  
Version Uploaded Documentation Archive
0.0.17 Jul 5, 2018 Go to the documentation of dartness 0.0.17 Download dartness 0.0.17 archive
0.0.16 May 24, 2018 Go to the documentation of dartness 0.0.16 Download dartness 0.0.16 archive
0.0.15 May 23, 2018 Go to the documentation of dartness 0.0.15 Download dartness 0.0.15 archive
0.0.14 May 21, 2018 Go to the documentation of dartness 0.0.14 Download dartness 0.0.14 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
14
Health:
Code health derived from static analysis. [more]
97
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
56
Learn more about scoring.

We analyzed this package on Aug 11, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.11.8

Platforms

Detected platforms: Flutter, other

Primary library: package:dartness/dartness.dart with components: io.

Suggestions

Package is pre-v1 release.

While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction of the API.

Fix lib/dartness.dart.

Analysis of lib/dartness.dart reported 2 hints:

line 30 col 30: 'ANY_IP_V4' is deprecated and shouldn't be used.

line 39 col 28: 'parseBody' is deprecated and shouldn't be used.

Format lib/src/middleware.dart.

Run dartfmt to format lib/src/middleware.dart.

Format lib/src/module.dart.

Run dartfmt to format lib/src/module.dart.

Format lib/src/router.dart.

Run dartfmt to format lib/src/router.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.40.0 <3.0.0
body_parser ^1.1.0 1.1.1
Transitive dependencies
charcode 1.1.2
collection 1.14.11
dart2_constant 1.0.2+dart2
http_parser 3.1.3
http_server 0.9.8
mime 0.9.6+2
path 1.6.2
source_span 1.4.1
string_scanner 1.0.3
typed_data 1.1.6
Dev dependencies
test ^0.12.37