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.

Isohttpd #

pub package

A lightweight http server that runs in an isolate. Powered by Iso

Example #

import 'dart:io';
import 'dart:async';
import 'package:isohttpd/isohttpd.dart';

Future<HttpResponse> handler(HttpRequest request, IsoLogger log) async {
  return jsonResponse(request, {"response": "ok"});
}

void main() async {
  // set routes
  final defaultRoute = IsoRoute(path: "*", handler: handler);
  final routes = <IsoRoute>[defaultRoute];
  final router = IsoRouter(routes);

  // run
  final iso = IsoHttpdRunner(host: "localhost", router: router);
  await iso.run(verbose: true);

  // listen to logs
  iso.logs.listen((String data) => print("$data"));
iso.requestLogs.listen((ServerRequestLog data) => print("=> $data"));
  // idle
  final waiter = Completer<Null>();
  await waiter.future;
}

Commands #

Start the server:

await iso.run(startServer: false);
iso.start();

Stop the server:

iso.stop();

Server status:

iso.status();

Utils #

Send a json response from a handler:

jsonResponse(request, {"response": "ok"});

Decode multipart/form-data:

final body = await decodeMultipartRequest(request);
final dynamic data = body.data;

List a directory's content:

final data = await directoryListing(Directory(somePath));
0
likes
40
pub points
14%
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