http_interop_io 0.8.0 http_interop_io: ^0.8.0 copied to clipboard
Interop-compatible wrapper over the standard dart:io HTTP server.
import 'dart:convert';
import 'dart:io';
import 'package:http_interop/http_interop.dart';
import 'package:http_interop_io/http_interop_io.dart';
Future<void> main() async {
final host = 'localhost';
final port = 8080;
final server = await HttpServer.bind(host, port);
server.listen(listener(sayHello));
ProcessSignal.sigint.watch().listen((event) async {
stderr.writeln('$event received, exiting');
await server.close(force: true);
exit(0);
});
print('Listening on http://$host:$port. Press Ctrl+C to stop.');
}
Future<Response> sayHello(Request request) async =>
Response(200, Body.text('Hello! ${DateTime.now()}', utf8), Headers());