restbackendtest

Last updated:

0 purchases

restbackendtest Image
restbackendtest Images
Add to Cart

Description:

restbackendtest

Dart Express #
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');
}
copied to clipboard
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');
}
copied to clipboard
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');
}
copied to clipboard
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');
}
copied to clipboard
Listening to Https requests
//listen for http requests
app.listen(port: 80, cb: (port) => print('listening for http on port $port'));

//assign certificate
var context = SecurityContext();
final chain = Platform.script.resolve('certificates/chain.pem').toFilePath();
final key = Platform.script.resolve('certificates/key.pem').toFilePath();

context.useCertificateChain(chain);
context.usePrivateKey(key);

//listen for https requests
app.listenHttps(
context,
port: 443,
cb: (port) => print('Listening for https on port $port'),
);
copied to clipboard
Currently supported View Engines #

Basic HTML
Mustache
Markdown
Jael

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.