angel_shelf 2.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 28

shelf #

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.

Usage #

embedShelf #

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;

2.0.0 #

  • Removed supportShelf.

1.2.0 #

  • 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 pub get

Alternatively, your editor might support pub get or flutter pub 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';
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 Jan 20, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4

Health issues and suggestions

Fix lib/src/convert.dart. (-59.27 points)

Analysis of lib/src/convert.dart failed with 3 errors, 7 hints, including:

line 42 col 30: The method 'parseRawRequestBuffer' isn't defined for the class 'HttpRequestContext'.

line 61 col 30: The method 'parseRawRequestBuffer' isn't defined for the class 'Http2RequestContext'.

line 86 col 24: The method 'parseRawRequestBuffer' isn't defined for the class 'RequestContext'.

line 38 col 7: Unnecessary new keyword.

line 41 col 20: Unnecessary new keyword.

Fix lib/src/embed_shelf.dart. (-1.99 points)

Analysis of lib/src/embed_shelf.dart reported 4 hints:

line 16 col 29: Use = to separate a named parameter from its default value.

line 17 col 10: This function has a return type of 'Future

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (stream_channel).

Package is getting outdated. (-18.90 points)

The package was last published 62 weeks ago.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev <3.0.0
angel_framework ^2.0.0-alpha 2.1.0
path ^1.0.0 1.6.4
shelf ^0.7.0 0.7.5
stream_channel ^1.0.0 1.7.0 2.0.0
Transitive dependencies
angel_container 1.1.0
angel_http_exception 1.1.0
angel_model 1.0.3
angel_route 3.1.0+1
async 2.4.0
charcode 1.1.2
code_buffer 1.0.1
collection 1.14.12
combinator 1.1.0
convert 2.1.1
crypto 2.1.4
dart2_constant 1.0.2+dart2
file 5.1.0
http2 1.0.0
http_parser 3.1.3
http_server 0.9.8+3
intl 0.16.1
logging 0.11.4
matcher 0.12.6
merge_map 1.0.2
meta 1.1.8
mime 0.9.6+3
mock_request 1.0.6
pedantic 1.9.0
quiver 2.1.2+1
quiver_hashcode 2.0.0
recase 2.0.1 3.0.0
source_span 1.6.0
stack_trace 1.9.3
string_scanner 1.0.5
term_glyph 1.1.0
tuple 1.0.3
typed_data 1.1.6
uuid 2.0.4
Dev dependencies
angel_test ^2.0.0-alpha
shelf_static ^0.2.8
test ^1.0.0