Skip to main content

http_interop_shelf 0.1.0 copy "http_interop_shelf: ^0.1.0" to clipboard
http_interop_shelf: ^0.1.0 copied to clipboard

Adapts http_interop handlers for use with Shelf.

example/example.dart

import 'dart:convert';
import 'dart:io';

import 'package:http_interop/extensions.dart';
import 'package:http_interop/http_interop.dart';
import 'package:http_interop_shelf/http_interop_shelf.dart';
import 'package:shelf/shelf_io.dart';

void main() async {
  const host = 'localhost';
  const port = 8080;
  final shelfHandler = echo.shelfHandler;
  final server = await serve(shelfHandler, host, port);
  ProcessSignal.sigint.watch().listen((event) async {
    print('Shutting down...');
    await server.close();
    exit(0);
  });
  print('Listening on http://$host:$port. Press Ctrl+C to exit.');
}

Future<Response> echo(Request request) async => Response(
  200,
  Body.json({
    'method': request.method,
    'body': await request.body.decode(utf8),
    'headers': request.headers,
  }),
  Headers.from({
    'Content-Type': ['application/json'],
  }),
);
1
likes
150
points
102
downloads

Documentation

API reference

Publisher

verified publisherkarapetov.com

Weekly Downloads

Adapts http_interop handlers for use with Shelf.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

http_interop, shelf

More

Packages that depend on http_interop_shelf