https://github.com/f3ath/dart-http-interop-shelf
http_interop shims for shelf
https://github.com/f3ath/dart-http-interop-shelf
Last synced: 3 months ago
JSON representation
http_interop shims for shelf
- Host: GitHub
- URL: https://github.com/f3ath/dart-http-interop-shelf
- Owner: f3ath
- License: mit
- Created: 2024-08-30T23:59:04.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-09-02T18:36:37.000Z (over 1 year ago)
- Last Synced: 2025-06-10T19:50:11.232Z (7 months ago)
- Language: Dart
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# http_interop_shelf
Converts Interop handlers to Shelf handlers.
```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;
/// The shelf handler
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.');
}
/// This is a http_interop handler that echos the request back to the client.
Future 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']
}));
```