Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/r8/shelf_flutter_asset
A simple handler for the Shelf ecosystem to serve files from Flutter assets.
https://github.com/r8/shelf_flutter_asset
dart flutter http server shelf
Last synced: about 1 month ago
JSON representation
A simple handler for the Shelf ecosystem to serve files from Flutter assets.
- Host: GitHub
- URL: https://github.com/r8/shelf_flutter_asset
- Owner: r8
- License: bsd-3-clause
- Created: 2023-01-21T19:17:49.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-07-04T13:39:10.000Z (over 1 year ago)
- Last Synced: 2025-01-04T03:05:38.507Z (about 1 month ago)
- Topics: dart, flutter, http, server, shelf
- Language: Dart
- Homepage:
- Size: 102 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# shelf_flutter_asset
[![build status](https://github.com/r8/shelf_flutter_asset/workflows/tests/badge.svg)](https://github.com/r8/shelf_flutter_asset/actions)
[![codecov](https://codecov.io/gh/r8/shelf_flutter_asset/branch/main/graph/badge.svg?token=DXWQ52MGBI)](https://codecov.io/gh/r8/shelf_flutter_asset)
[![pub package](https://img.shields.io/pub/v/shelf_flutter_asset.svg)](https://pub.dev/packages/shelf_flutter_asset)
[![package publisher](https://img.shields.io/pub/publisher/shelf_flutter_asset.svg)](https://pub.dev/packages/shelf_flutter_asset/publisher)A simple handler for the Shelf ecosystem to serve files from Flutter assets.
## Usage
Bind as root handler:
```dart
import 'package:shelf/shelf_io.dart' as io;
import 'package:shelf_flutter_asset/shelf_flutter_asset.dart';void main() {
var assetHandler = createAssetHandler(defaultDocument: 'index.html');io.serve(assetHandler, 'localhost', 8080);
}
```Bind with [`shelf_router`](https://pub.dev/packages/shelf_router):
```dart
import 'package:shelf_router/shelf_router.dart';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as io;void main() {
var app = Router();
final assetHandler = createAssetHandler();app.get('/hello', (Request request) {
return Response.ok('hello-world');
});app.get('/assets/', (Request request) {
return assetHandler(request.change(path: 'assets'));
});io.serve(app, 'localhost', 8080);
}
```Bind with [`shelf_router`](https://pub.dev/packages/shelf_router) and custom root path:
```dart
import 'package:shelf_router/shelf_router.dart';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as io;void main() {
var app = Router();
final assetHandler = createAssetHandler(rootPath: 'assets/html');app.get('/hello', (Request request) {
return Response.ok('hello-world');
});app.get('/assets/', (Request request) {
return assetHandler(request.change(path: 'assets/html'));
});io.serve(app, 'localhost', 8080);
}
```