dart_express 0.5.3 copy "dart_express: ^0.5.3" to clipboard
dart_express: ^0.5.3 copied to clipboard

An unopinionated express-like HTTP framework built in Dart, includes the ability to render Mustache, Jael and HTML files, and simple routing.

Dart Express Dart CI #

An express-like web server framework for Dart developers.

Usage #

A simple usage example:

import 'package:dart_express/dart_express.dart';

main() {
  final 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() {
  final 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() {
  final 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() {
  final app = express();

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

  app.settings
    ..viewsPath = 'custom_views_path'
    ..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
  • Markdown
  • Jael
16
likes
40
points
57
downloads

Publisher

unverified uploader

Weekly Downloads

An unopinionated express-like HTTP framework built in Dart, includes the ability to render Mustache, Jael and HTML files, and simple routing.

Repository (GitHub)
View/report issues

License

BSD-2-Clause (license)

Dependencies

code_buffer, file, http, jael, jael_preprocessor, markdown, meta, mustache4dart, path, path_to_regexp, symbol_table

More

Packages that depend on dart_express