dart_express 0.2.3

  • Readme
  • Changelog
  • Example
  • Installing
  • 66

An express-like web server framework for Dart developers.

Usage #

A simple usage example:

import 'package:dart_express/dart_express.dart';

main() {
  var app = express();

  app.get('/', (req, res) {
    res.json({
      'hello': 'world',
      'test': true,
    });
  });

  app.listen(3000, (port) => print('Listening on port $port');
}

Example with route parameters

import 'package:dart_express/dart_express.dart';

main() {
  var app = express();

  app.get('/users/:userId/posts/:postId', (req, res) {
    res.json({
      'userId': req.params['userId'],
      'postId': req.params['postId'],
    });
  });

  app.listen(3000, (port) => print('Listening on port $port');
}

With Body parsing Middleware:

import 'package:dart_express/dart_express.dart';

main() {
  var app = express();

  app.use(BodyParser.json());

  app.post('/post', (req, res) {
    print(req.body);

    res.send({
      'request_body': req.body,
    });
  });

  app.listen(3000, (port) => print('Listening on port $port');
}

Using the mustache templating engine

import 'package:dart_express/dart_express.dart';

main() {
  var app = express();

  app.use(BodyParser.json());
  app.engine(MustacheEngine.use());

  app.settings.viewsPath = 'custom_views_path';
  app.settings.viewEngine = 'mustache';

  app.get('/', (req, res) {
    res.render('index', {
      'app_name': 'My Test App',
    });
  });

  app.listen(3000, (port) => print('Listening on port $port');
}

Currently supported View Engines #

  • Basic HTML
  • Mustache
  • Jael

Roadmap #

  • [x] Basic Routing
  • [x] Easily build Middleware
  • [x] Add & use view engines easily
  • [ ] Add in-depth testing
  • [ ] Clean up imports and extract middleware to separate packages
  • [ ] Add Dart "morgan" middleware package for logging HTTP requests
  • [ ] Add CORS middleware package

0.1.0 #

  • Initial version of Dart express with basic functionality for routing and middleware

0.1.1 #

  • Add dependencies for Jael (will be breaking this out to a separate package later)

0.2.0 #

  • Add path_to_regexp package to improve route matching.
  • Add support for route parameters using path_to_regexp package.
  • Improve README to include additional documentation
  • Add res.end() and res.location() methods to Response class.

0.2.1 #

  • Clean up Request & Response classes
  • Export HTTPStatus class from dart-express directly

0.2.2 #

  • Fix issue with relative paths for views
  • Add app.set('views', './path');
  • Add app.set('view engine', './path')

0.2.3 #

  • Throw error when providing an invalid setting key

example/dart_express_example.dart

import 'package:dart_express/dart_express.dart';

const int PORT = 5000;

main() {
  var app = express();

  app.use(BodyParser.json());

  app.engine(MustacheEngine.use());
  app.engine(JaelEngine.use());
  app.settings.viewEngine = 'mustache';

  app.get('/', (req, res) {
    res.statusCode = HttpStatus.ok;

    res.json({
      'hello': 'world',
      'age': 25,
    });
  });

  app.all('/secret', (req, res) {
    print('Accessing the secret section');

    req.next();
  });

  app.get('/secret', (req, res) {
    res.send('Secret Home Page');
  });

  app.get('/secret/2', (req, res) {
    res.send('Secret home page 2');
  });

  app.get('/2', (req, res) {
    res.render('index');
  });

  app.get('/3', (req, res) {
    res.render('about', {
      'first_name': req.params['first_name'] ?? 'Devin Riegle',
      'person': req.params['person']
    });
  });

  app.get('/4', (req, res) {
    res.render(
      'test.jael',
      {'template_engine': 'Jael', 'first_name': 'Thosakwe'},
    );
  });

  app.post('/post', (req, res) {
    res.send('Data from post :)');
  });

  app.get('/users/:userId/posts/:postId', (req, res) {
    print(req.params);

    res.render(
      'test.jael',
      {'template_engine': req.params['postId'], 'first_name': 'George'},
    );
  });

  app.listen(PORT, (int port) => print('Listening on port $port'));
}

Use this package as a library

1. Depend on it

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


dependencies:
  dart_express: ^0.2.3

2. Install it

You can install packages from the command line:

with pub:


$ pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:dart_express/dart_express.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
36
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
66
Learn more about scoring.

We analyzed this package on Jul 2, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13

Analysis suggestions

Package not compatible with SDK flutter

Because it is not compatible with any of the supported runtimes: flutter-native, flutter-web

Package not compatible with runtime flutter-native on android

Because of the import of dart:mirrors via the import chain package:dart_express/dart_express.dartpackage:dart_express/src/engines/jael.dartpackage:jael_preprocessor/jael_preprocessor.dartpackage:jael/jael.dartpackage:jael/src/renderer.dartpackage:jael/src/text/scanner.dartpackage:jael/src/ast/ast.dartpackage:jael/src/ast/new.dartpackage:jael/src/ast/member.dartdart:mirrors

Package not compatible with runtime flutter-native on ios

Because of the import of dart:mirrors via the import chain package:dart_express/dart_express.dartpackage:dart_express/src/engines/jael.dartpackage:jael_preprocessor/jael_preprocessor.dartpackage:jael/jael.dartpackage:jael/src/renderer.dartpackage:jael/src/text/scanner.dartpackage:jael/src/ast/ast.dartpackage:jael/src/ast/new.dartpackage:jael/src/ast/member.dartdart:mirrors

Package not compatible with runtime flutter-native on linux

Because of the import of dart:mirrors via the import chain package:dart_express/dart_express.dartpackage:dart_express/src/engines/jael.dartpackage:jael_preprocessor/jael_preprocessor.dartpackage:jael/jael.dartpackage:jael/src/renderer.dartpackage:jael/src/text/scanner.dartpackage:jael/src/ast/ast.dartpackage:jael/src/ast/new.dartpackage:jael/src/ast/member.dartdart:mirrors

Package not compatible with runtime flutter-native on macos

Because of the import of dart:mirrors via the import chain package:dart_express/dart_express.dartpackage:dart_express/src/engines/jael.dartpackage:jael_preprocessor/jael_preprocessor.dartpackage:jael/jael.dartpackage:jael/src/renderer.dartpackage:jael/src/text/scanner.dartpackage:jael/src/ast/ast.dartpackage:jael/src/ast/new.dartpackage:jael/src/ast/member.dartdart:mirrors

Package not compatible with runtime flutter-native on windows

Because of the import of dart:mirrors via the import chain package:dart_express/dart_express.dartpackage:dart_express/src/engines/jael.dartpackage:jael_preprocessor/jael_preprocessor.dartpackage:jael/jael.dartpackage:jael/src/renderer.dartpackage:jael/src/text/scanner.dartpackage:jael/src/ast/ast.dartpackage:jael/src/ast/new.dartpackage:jael/src/ast/member.dartdart:mirrors

Package not compatible with runtime flutter-web on web

Because of the import of dart:mirrors via the import chain package:dart_express/dart_express.dartpackage:dart_express/src/engines/jael.dartpackage:jael_preprocessor/jael_preprocessor.dartpackage:jael/jael.dartpackage:jael/src/renderer.dartpackage:jael/src/text/scanner.dartpackage:jael/src/ast/ast.dartpackage:jael/src/ast/new.dartpackage:jael/src/ast/member.dartdart:mirrors

Package not compatible with runtime native-aot

Because of the import of dart:mirrors via the import chain package:dart_express/dart_express.dartpackage:dart_express/src/engines/jael.dartpackage:jael_preprocessor/jael_preprocessor.dartpackage:jael/jael.dartpackage:jael/src/renderer.dartpackage:jael/src/text/scanner.dartpackage:jael/src/ast/ast.dartpackage:jael/src/ast/new.dartpackage:jael/src/ast/member.dartdart:mirrors

Package not compatible with runtime web

Because of the import of dart:mirrors via the import chain package:dart_express/dart_express.dartpackage:dart_express/src/engines/jael.dartpackage:jael_preprocessor/jael_preprocessor.dartpackage:jael/jael.dartpackage:jael/src/renderer.dartpackage:jael/src/text/scanner.dartpackage:jael/src/ast/ast.dartpackage:jael/src/ast/new.dartpackage:jael/src/ast/member.dartdart:mirrors

Health suggestions

Fix lib/src/app.dart. (-0.50 points)

Analysis of lib/src/app.dart reported 1 hint:

line 1 col 65: The name Directory is shown, but isn’t used.

Format lib/src/request.dart.

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

Format lib/src/response.dart.

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

Format lib/src/router.dart.

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

Format lib/src/view.dart.

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

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (path_to_regexp).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.3.0 <3.0.0
code_buffer ^1.0.1 1.0.1
file ^5.0.0 5.2.1
http ^0.12.0+2 0.12.1
jael ^2.0.2 2.0.2
jael_preprocessor ^2.0.0 2.0.1
meta ^1.1.7 1.1.8
mustache4dart ^3.0.0-dev.0.0 3.0.0-dev.1.0
path ^1.6.4 1.7.0
path_to_regexp ^0.2.1 0.2.1 0.3.0
symbol_table ^2.0.0 2.0.0
Transitive dependencies
_fe_analyzer_shared 4.0.0 5.0.0
analyzer 0.39.10 0.39.11
args 1.6.0
async 2.4.1
build 1.3.0
build_config 0.4.2
build_daemon 2.1.4
build_resolvers 1.3.9
build_runner 1.10.0
build_runner_core 5.2.0 6.0.0
built_collection 4.3.2
built_value 7.1.0
charcode 1.1.3
checked_yaml 1.0.2
code_builder 3.3.0
collection 1.14.13
convert 2.1.1
crypto 2.1.5
csslib 0.16.1
dart_style 1.3.6
fixnum 0.10.11
glob 1.2.0
graphs 0.2.0
html 0.14.0+3
http_multi_server 2.2.0
http_parser 3.1.4
intl 0.16.1
io 0.3.4
js 0.6.2
json_annotation 3.0.1
logging 0.11.4
matcher 0.12.8
mime 0.9.6+3
node_interop 1.1.1
node_io 1.1.1
package_config 1.9.3
pool 1.4.0
pub_semver 1.4.4
pubspec_parse 0.1.5
quiver 2.1.3
reflectable 2.2.5
shelf 0.7.7
shelf_web_socket 0.2.3
source_span 1.7.0
stack_trace 1.9.5
stream_channel 2.0.0
stream_transform 1.2.0
string_scanner 1.0.5
term_glyph 1.1.0
timing 0.1.1+2
typed_data 1.2.0
watcher 0.9.7+15
web_socket_channel 1.1.0
yaml 2.2.1
Dev dependencies
pedantic ^1.8.0 1.9.0 1.9.1
test ^1.6.0