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

outdated

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

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'));
}
16
likes
0
pub points
0%
popularity

Publisher

unverified uploader

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

unknown (license)

Dependencies

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

More

Packages that depend on dart_express