The Protevus Platform: Unified Full-Stack Development https://protevus.com
Find a file
Tobe Osakwe aacd91e267
Merge pull request #5 from tvolkert/http
Prepare for upcoming change to HttpRequest and HttpClientResponse
2019-07-08 20:17:26 -04:00
.idea Logging for test handlers 2018-01-08 16:04:52 -05:00
example 2.0.0 2018-11-11 12:35:37 -05:00
lib 2.0.0 2018-11-11 12:35:37 -05:00
test Prepare for upcoming change to HttpRequest and HttpClientResponse 2019-06-25 19:50:57 -07:00
.gitignore rm dart tool 2018-11-11 12:36:03 -05:00
.travis.yml 1.0.0 2017-01-13 10:33:35 -05:00
analysis_options.yaml 2.0.0 2018-11-11 12:35:37 -05:00
CHANGELOG.md 2.0.0 2018-11-11 12:35:37 -05:00
LICENSE Initial commit 2016-12-01 17:32:04 -05:00
pubspec.yaml 2.0.0 2018-11-11 12:35:37 -05:00
README.md 2.0.0 2018-11-11 12:35:37 -05:00

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.
  app.fallback(embedShelf(
    new shelf.Pipeline()
      .addMiddleware(shelf.logRequests())
      .addHandler(_echoRequest)
  ));

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

  await http.startServer(InternetAddress.loopbackIPV4, 3000);
  print(http.uri);
}

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;
  container.make<Truck>().drive();
}