dart_express 0.2.2 dart_express: ^0.2.2 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.
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'));
}