isohttpd 0.5.0 copy "isohttpd: ^0.5.0" to clipboard
isohttpd: ^0.5.0 copied to clipboard

A lightweight http server that runs in an isolate. Router and logs are included.

example/README.md

Examples #

Command line example:

Future<HttpResponse> handler(HttpRequest request, IsoLogger log) async {
  request.response.statusCode = HttpStatus.ok;
  return request.response;
}

Future<String> initHost() async {
  final interfaces = await NetworkInterface.list(
      includeLoopback: false, type: InternetAddressType.any);
  return interfaces.first.addresses.first.address;
}

void main() async {
  // set routes
  IsoRoute onGet = IsoRoute(path: "*", handler: handler);
  List<IsoRoute> routes = <IsoRoute>[onGet];
  final router = IsoRouter(routes);
  // set host
  String host = await initHost();
  // run
  print("Running the server in an isolate");
  IsoHttpdRunner iso = IsoHttpdRunner(host: host, router: router);
  await iso.run(verbose: true);
  // listen to logs
  iso.logs.listen((dynamic data) => print("$data"));
  iso.requestLogs.listen((dynamic data) => print("REQUEST $data"));
  // idle
  while (true) {}
}
0
likes
40
pub points
0%
popularity

Publisher

unverified uploader

A lightweight http server that runs in an isolate. Router and logs are included.

Repository (GitHub)
View/report issues

License

MIT (LICENSE)

Dependencies

body_parser, emodebug, extra_pedantic, iso, meta, path, pedantic

More

Packages that depend on isohttpd