angel_shelf 2.0.0

  • Example
  • Installing
  • Versions
  • 54


Pub build status

Shelf interop with Angel. This package lets you run package:shelf handlers via a custom adapter.

Use the code in this repo to embed existing shelf apps into your Angel applications. This way, you can migrate legacy applications without having to rewrite your business logic.

This will make it easy to layer your API over a production application, rather than having to port code.



This is a compliant shelf adapter that acts as an Angel request handler. You can use it as a middleware, or attach it to individual routes.

import 'dart:io';
import 'package:angel_framework/angel_framework.dart';
import 'package:angel_shelf/angel_shelf.dart';
import 'package:shelf/shelf.dart' as shelf;
import 'api/api.dart';

main() async {
  var app = new Angel();
  var http = new AngelHttp(app);

  // Angel routes on top
  await app.mountController<ApiController>();

  // Re-route all other traffic to an
  // existing application.
    new shelf.Pipeline()

  // Or, only on a specific route:
  app.get('/shelf', wrappedShelfHandler);

  await http.startServer(InternetAddress.loopbackIPV4, 3000);

Communicating with Angel with embedShelf

You can communicate with Angel:

handleRequest(shelf.Request request) {
  // Access original Angel request...
  var req = request.context['angel_shelf.request'] as RequestContext;

  // ... And then interact with it.
  req.container.registerNamedSingleton<Foo>('from_shelf', new Foo());

  // `req.container` is also available.
  var container = request.context['angel_shelf.container'] as Container;


  • Removed supportShelf.


  • Upgraded for >=1.1.0 compatibility.


import 'dart:io';
import 'package:angel_framework/angel_framework.dart';
import 'package:angel_framework/http.dart';
import 'package:angel_shelf/angel_shelf.dart';
import 'package:shelf_static/shelf_static.dart';

main() async {
  var app = new Angel();
  var http = new AngelHttp(app);

  // `shelf` request handler
  var shelfHandler = createStaticHandler('.',
      defaultDocument: 'index.html', listDirectories: true);

  // Use `embedShelf` to adapt a `shelf` handler for use within Angel.
  var wrappedHandler = embedShelf(shelfHandler);

  // A normal Angel route.
  app.get('/angel', (req, ResponseContext res) {
    res.write('Hooray for `package:angel_shelf`!');
    return false; // End execution of handlers, so we don't proxy to when we don't need to.

  // Proxy any other request through to the static file handler

  await http.startServer(InternetAddress.loopbackIPv4, 8080);
  print('Proxying at ${http.uri}');

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  angel_shelf: ^2.0.0

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:angel_shelf/angel_shelf.dart';
Version Uploaded Documentation Archive
2.0.0 Nov 11, 2018 Go to the documentation of angel_shelf 2.0.0 Download angel_shelf 2.0.0 archive
1.2.0 Jan 9, 2018 Go to the documentation of angel_shelf 1.2.0 Download angel_shelf 1.2.0 archive
1.1.1 Jun 20, 2017 Go to the documentation of angel_shelf 1.1.1 Download angel_shelf 1.1.1 archive
1.1.0 Jun 12, 2017 Go to the documentation of angel_shelf 1.1.0 Download angel_shelf 1.1.0 archive
1.0.0 Jan 13, 2017 Go to the documentation of angel_shelf 1.0.0 Download angel_shelf 1.0.0 archive
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Dec 5, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.7


Detected platforms: Flutter, other

Primary library: package:angel_shelf/angel_shelf.dart with components: io, isolate.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev <3.0.0
angel_framework ^2.0.0-alpha 2.0.0-alpha.14
path ^1.0.0 1.6.2
shelf ^0.7.0 0.7.3+3
stream_channel ^1.0.0 1.6.8
Transitive dependencies
angel_container 1.0.0
angel_http_exception 1.0.0+3
angel_model 1.0.0+1
angel_route 3.0.0
async 2.0.8
body_parser 1.1.1
charcode 1.1.2
code_buffer 1.0.1
collection 1.14.11
combinator 1.0.0+3
convert 2.0.2
crypto 2.0.6
dart2_constant 1.0.2+dart2
file 5.0.6
http2 0.1.9
http_parser 3.1.3
http_server 0.9.8+1
intl 0.15.7
logging 0.11.3+2
matcher 0.12.4
merge_map 1.0.1
meta 1.1.6
mime 0.9.6+2
mock_request 1.0.4
quiver 2.0.1
source_span 1.4.1
stack_trace 1.9.3
string_scanner 1.0.4
tuple 1.0.2
typed_data 1.1.6
uuid 1.0.3
Dev dependencies
angel_test ^2.0.0-alpha
shelf_static ^0.2.8
test ^1.0.0