dartness 0.0.16

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

Dartness

minimalist web middleware based micro 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

Roadmap:

  • add regexp routes
  • add logger
  • add middleware to single route/routes list
  • 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.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.16"

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

Analysis

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

  • Dart: 2.0.0-dev.63.0
  • pana: 0.11.3

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
0 / 100
Health:
Code health derived from static analysis. [more]
99 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
50
Learn more about scoring.

Platforms

Detected platforms: Flutter, other

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

Suggestions

  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

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

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 2 hints.

    Strong-mode analysis of lib/dartness.dart gave the following hint:

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

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.0
Transitive dependencies
charcode 1.1.1
collection 1.14.10
http_parser 3.1.2
http_server 0.9.7
mime 0.9.6+1
path 1.6.1
source_span 1.4.0
string_scanner 1.0.2
typed_data 1.1.5
Dev dependencies
test ^0.12.37