flutter_express 0.8.4 copy "flutter_express: ^0.8.4" to clipboard
flutter_express: ^0.8.4 copied to clipboard

Flutter_Express is a lightweight and user-friendly api routing package.

example/flutter_express_example.dart

import 'package:flutter_express/flutter_express.dart';
import 'package:flutter_express/middlewares.dart';

void main() {
  final app = FlutterExpress();
  const portNumber = 3000;

  // add middleware for every routes
  app.use("*", [cors()]);

  app.use("/*", [
    (req, res, next) {
      print(req.method);
      next();
    }
  ]);

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

  app.get("/names/:name/*", (req, res) {
    print("name ${req.params['name']}");
    res.json({"name": req.params['name']});
  });

  // add a middleware for "/post" route
  app.post("/post", (req, res) {
    res.json(req.body);
  }, middlewares: [Parser.jsonParser]);

  app.listen(portNumber, () {
    print('Listening on port $portNumber');
  });
  app.get('/ip', (req, res) async {
    res.json({
      'ip': 3000,
      'ws': 'ws://3000:8000',
      'wsPort': 8000,
    });
  });
}
6
likes
160
points
91
downloads

Publisher

unverified uploader

Weekly Downloads

Flutter_Express is a lightweight and user-friendly api routing package.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

collection, http_parser, shelf

More

Packages that depend on flutter_express