sevr 1.0.2+3 copy "sevr: ^1.0.2+3" to clipboard
sevr: ^1.0.2+3 copied to clipboard

outdated

A library to easily create http servers with Dart and perform Http requests.

example/example.dart

import 'dart:io';
import 'package:sevr/sevr.dart';
import 'package:path/path.dart' as p;

main() {
  var serv = Sevr();
  serv.use(Sevr.static('./web'));

  //We can create controller,middleware classes etc, put them in a list and pass them into the router methods
  serv.get('/file', [
    (ServRequest req, ServResponse res) {
      return res.status(200).sendFile(p.absolute('web/index.html'));
    }
  ]);

  serv.get('/test', [
    (ServRequest req, ServResponse res) {
      return res.status(200).json({'status': 'ok'});
    }
  ]);

  serv.post('/post', [
    (ServRequest req, ServResponse res) async {
      return res.status(200).json(req.body);
    }
  ]);

  serv.listen(4000, callback: () {
    print('Listening on port: ${4000}');
  });
}

//  controllerClassOne(req,res)async{
//   res.locals['response'] = req.body;
// }

// controllerReturn(req,res){
//   print('running the second function');
//   return res.status(200).json(res.locals['response']);
// }
16
likes
0
pub points
31%
popularity

Publisher

unverified uploader

A library to easily create http servers with Dart and perform Http requests.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

body_parser, dart2_constant, mime, path, pedantic

More

Packages that depend on sevr