angel_framework 2.0.0-alpha.18

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 76

angel_framework #

Pub build status

A high-powered HTTP server with support for dependency injection, sophisticated routing and more.

This is the core of the Angel framework. To build real-world applications, please see the homepage.

import 'package:angel_container/mirrors.dart';
import 'package:angel_framework/angel_framework.dart';

main() async {
    var app = new Angel(reflector: MirrorsReflector());

    // Index route. Returns JSON.
    app.get('/', (req, res) => res.write('Welcome to Angel!'));
  
    // Accepts a URL like /greet/foo or /greet/bob.
    app.get(
      '/greet/:name',
      (req, res) {
        var name = req.params['name'];
        res
          ..write('Hello, $name!')
          ..close();
      },
    );
    
    // Pattern matching - only call this handler if the query value of `name` equals 'emoji'.
    app.get(
      '/greet',
      ioc((@Query('name', match: 'emoji') String name) => '😇🔥🔥🔥'),
    );
    
    // Handle any other query value of `name`.
    app.get(
      '/greet',
      ioc((@Query('name') String name) => 'Hello, $name!'),
    );
    
    // Simple fallback to throw a 404 on unknown paths.
    app.fallback((req, res) {
      throw new AngelHttpException.notFound(
        message: 'Unknown path: "${req.uri.path}"',
      );
    });

    var http = new AngelHttp(app);
    var server = await http.startServer('127.0.0.1', 3000);
    var url = 'http://${server.address.address}:${server.port}';
    print('Listening at $url');
    print('Visit these pages to see Angel in action:');
    print('* $url/greet/bob');
    print('* $url/greet/?name=emoji');
    print('* $url/greet/?name=jack');
    print('* $url/nonexistent_page');
}

2.0.0-alpha.18 #

  • Upgrade http2 dependency.
  • Upgrade uuid dependency.
  • Fixed a bug that prevented body parsing from ever completing with http2.
  • Add Providers.hashCode.

2.0.0-alpha.17 #

  • Revert the migration to lumberjack for now. In the future, when it's more stable, there'll be a conversion, perhaps.

2.0.0-alpha.16 #

  • Use package:lumberjack for logging.

2.0.0-alpha.15 #

  • Remove dependency on body_parser.
  • RequestContext now exposes a Stream<List<int>> get body getter.
    • Calling RequestContext.parseBody() parses its contents.
    • Added bodyAsMap, bodyAsList, bodyAsObject, and uploadedFiles to RequestContext.
    • Removed Angel.keepRawRequestBuffers and anything that had to do with buffering request bodies.

2.0.0-alpha.14 #

  • Patch HttpResponseContext._openStream to send content-length.

2.0.0-alpha.13 #

  • Fixed a logic error in HttpResponseContext that prevented status codes from being sent.

2.0.0-alpha.12 #

  • Remove ResponseContext.sendFile.
  • Add Angel.mimeTypeResolver.
  • Fix a bug where an unknown MIME type on streamFile would return a 500.

2.0.0-alpha.11 #

  • Add readMany to Service.
  • Allow ResponseContext.redirect to take a Uri.
  • Add Angel.mountController.
  • Add Angel.findServiceOf.
  • Roll in HTTP/2. See pkg:angel_framework/http2.dart.

2.0.0-alpha.10 #

  • All calls to Service.parseId are now affixed with the <Id> argument.
  • Added uri getter to AngelHttp.
  • The default for parseQuery now wraps query parameters in new Map<String, dynamic>.from. This resolves a bug in package:angel_validate.

2.0.0-alpha.9 #

  • Add Service.map.

2.0.0-alpha.8 #

  • No longer export HTTP-specific code from angel_framework.dart. An import of import 'package:angel_framework/http.dart'; will be necessary in most cases now.

2.0.0-alpha.7 #

  • Force a tigher contract on services. They now must return Data on all methods except for index, which returns a List<Data>.

2.0.0-alpha.6 #

  • Allow passing a custom Container to handleContained and co.

2.0.0-alpha.5 #

  • MapService methods now explicitly return Map<String, dynamic>.

2.0.0-alpha.4 #

  • Renamed waterfall to chain.
  • Renamed Routable.service to Routable.findService.
    • Also Routable.findHookedService.

2.0.0-alpha.3 #

  • Added <Id, Data> type parameters to Service.
  • HookedService now follows suit, and takes a third parameter, pointing to the inner service.
  • Routable.use now uses the generic parameters added to Service.
  • Added generic usage to HookedServiceListener, etc.
  • All service methods take Map<String, dynamic> as params now.

2.0.0-alpha.2 #

  • Added ResponseContext.detach.

2.0.0-alpha.1 #

  • Removed Angel.injectEncoders.
  • Added Providers.toJson.
  • Moved Providers.graphql to Providers.graphQL.
  • Angel.optimizeForProduction no longer calls preInject, as it does not need to.
  • Rename ResponseContext.enableBuffer to ResponseContext.useBuffer.

2.0.0-alpha #

  • Removed random_string dependency.
  • Moved reflection to package:angel_container.
  • Upgraded package:file to 5.0.0.
  • ResponseContext.sendFile now uses package:file.
  • Abandon ContentType in favor of MediaType.
  • Changed view engine to use Map<String, dynamic>.
  • Remove dependency on package:json_god by default.
  • Remove dependency on package:dart2_constant.
  • Moved lib/hooks.dart into package:angel_hooks.
  • Moved TypedService into package:angel_typed_service.
  • Completely removed the AngelBase class.
  • Removed all @deprecated symbols.
  • Service.toId was renamed to Service.parseId; it also now uses its single type argument to determine how to parse a value. * In addition, this method was also made static.
  • RequestContext and ResponseContext are now generic, and take a single type argument pointing to the underlying request/response type, respectively.
  • RequestContext.io and ResponseContext.io are now permanently gone.
  • HttpRequestContextImpl and HttpResponseContextImpl were renamed to HttpRequestContext and HttpResponseContext.
  • Lazy-parsing request bodies is now the default; Angel.lazyParseBodies was replaced with Angel.eagerParseRequestBodies.
  • Angel.storeOriginalBuffer -> Angel.storeRawRequestBuffers.
  • The methods lazyBody, lazyFiles, and lazyOriginalBuffer on ResponseContext were all replaced with parseBody, parseUploadedFiles, and parseRawRequestBuffer, respectively.
  • Removed the synchronous equivalents of the above methods (body, files, and originalBuffer), as well as query.
  • Removed Angel.injections and RequestContext.injections.
  • Removed Angel.inject and RequestContext.inject.
  • Removed a dependency on package:pool, which also meant removing AngelHttp.throttle.
  • Remove the RequestMiddleware typedef; from now on, one should use ResponseContext.end exclusively to close responses.
  • waterfall will now only accept RequestHandler.
  • Routable, and all of its subclasses, now extend Router<RequestHandler>, and therefore only take routes in the form of FutureOr myFunc(RequestContext, ResponseContext res).
  • @Middleware now takes an Iterable of RequestHandlers.
  • @Expose.path now must be a String, not just any Pattern.
  • @Expose.middleware now takes Iterable<RequestHandler>, instead of just List.
  • createDynamicHandler was renamed to ioc, and is now used to run IoC-aware handlers in a type-safe manner.
  • RequestContext.params is now a Map<String, dynamic>, rather than just a Map.
  • Removed RequestContext.grab.
  • Removed RequestContext.properties.
  • Removed the defunct debug property where it still existed.
  • Routable.use now only accepts a Service.
  • Removed Angel.createZoneForRequest.
  • Removed Angel.defaultZoneCreator.
  • Added all flags to the Angel constructor, ex. Angel.eagerParseBodies.
  • Fix a bug where synchronous errors in handleRequest would not be caught.
  • AngelHttp.useZone now defaults to false.
  • ResponseContext now starts in streaming mode by default; the response buffer is opt-in, as in many cases it is unnecessary and slows down response time.
  • ResponseContext.streaming was replaced by ResponseContext.isBuffered.
  • Made LockableBytesBuilder public.
  • Removed the now-obsolete ResponseContext.willCloseItself.
  • Removed ResponseContext.dispose.
  • Removed the now-obsolete ResponseContext.end.
  • Removed the now-obsolete ResponseContext.releaseCorrespondingRequest.
  • preInject now takes a Reflector as its second argument.
  • Angel.reflector defaults to const EmptyReflector(), disabling reflection out-of-the-box.

example/main.dart

import 'package:angel_container/mirrors.dart';
import 'package:angel_framework/angel_framework.dart';
import 'package:angel_framework/http.dart';
import 'package:logging/logging.dart';

main() async {
  var app = new Angel(
    logger: Logger('angel'),
    reflector: MirrorsReflector(),
  );

  app.logger = new Logger('angel')
    ..onRecord.listen((rec) {
      print(rec);
      if (rec.error != null) print(rec.error);
      if (rec.stackTrace != null) print(rec.stackTrace);
    });

  // Index route. Returns JSON.
  app.get('/', (req, res) => 'Welcome to Angel!');

  // Accepts a URL like /greet/foo or /greet/bob.
  app.get(
    '/greet/:name',
    (req, res) {
      var name = req.params['name'];
      res
        ..write('Hello, $name!')
        ..close();
    },
  );

  // Pattern matching - only call this handler if the query value of `name` equals 'emoji'.
  app.get(
    '/greet',
    ioc((@Query('name', match: 'emoji') String name) => '😇🔥🔥🔥'),
  );

  // Handle any other query value of `name`.
  app.get(
    '/greet',
    ioc((@Query('name') String name) => 'Hello, $name!'),
  );

  // Simple fallback to throw a 404 on unknown paths.
  app.fallback((req, res) {
    throw new AngelHttpException.notFound(
      message: 'Unknown path: "${req.uri.path}"',
    );
  });

  var http = new AngelHttp(app);
  var server = await http.startServer('127.0.0.1', 3000);
  var url = 'http://${server.address.address}:${server.port}';
  print('Listening at $url');
  print('Visit these pages to see Angel in action:');
  print('* $url/greet/bob');
  print('* $url/greet/?name=emoji');
  print('* $url/greet/?name=jack');
  print('* $url/nonexistent_page');
}

Use this package as a library

1. Depend on it

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


dependencies:
  angel_framework: ^2.0.0-alpha.18

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_framework/angel_framework.dart';
  
Version Uploaded Documentation Archive
1.1.5+1 Aug 4, 2018 Go to the documentation of angel_framework 1.1.5+1 Download angel_framework 1.1.5+1 archive
1.1.5 Jul 12, 2018 Go to the documentation of angel_framework 1.1.5 Download angel_framework 1.1.5 archive
1.1.4+11 Jul 9, 2018 Go to the documentation of angel_framework 1.1.4+11 Download angel_framework 1.1.4+11 archive
1.1.4+10 Jul 9, 2018 Go to the documentation of angel_framework 1.1.4+10 Download angel_framework 1.1.4+10 archive
1.1.4+9 Jul 9, 2018 Go to the documentation of angel_framework 1.1.4+9 Download angel_framework 1.1.4+9 archive
1.1.4+7 Jun 27, 2018 Go to the documentation of angel_framework 1.1.4+7 Download angel_framework 1.1.4+7 archive
1.1.4+6 Jun 23, 2018 Go to the documentation of angel_framework 1.1.4+6 Download angel_framework 1.1.4+6 archive
1.1.4+5 Jun 23, 2018 Go to the documentation of angel_framework 1.1.4+5 Download angel_framework 1.1.4+5 archive
1.1.4+4 Jun 20, 2018 Go to the documentation of angel_framework 1.1.4+4 Download angel_framework 1.1.4+4 archive
1.1.4+3 Jun 10, 2018 Go to the documentation of angel_framework 1.1.4+3 Download angel_framework 1.1.4+3 archive

All 180 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
82
Health:
Code health derived from static analysis. [more]
53
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
95
Overall:
Weighted score of the above. [more]
76
Learn more about scoring.

We analyzed this package on Apr 4, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.2.0
  • pana: 0.12.14

Platforms

Detected platforms: Flutter, other

Primary library: package:angel_framework/angel_framework.dart with components: io.

Health issues and suggestions

Fix lib/src/core/driver.dart. (-25 points)

Analysis of lib/src/core/driver.dart failed with 1 error:

line 110 col 15: The argument type 'ParseResult<RouteResult>' can't be assigned to the parameter type 'ParseResult<Map<String, dynamic>>'.

Fix lib/src/core/server.dart. (-8.28 points)

Analysis of lib/src/core/server.dart reported 1 warning, 7 hints, including:

line 149 col 8: Parameters can't override default values, this method overrides 'Router.addRoute' where 'middleware' has a different value.

line 149 col 43: Use = to separate a named parameter from its default value.

line 215 col 20: Use = to separate a named parameter from its default value.

line 216 col 17: Use = to separate a named parameter from its default value.

line 217 col 24: Use = to separate a named parameter from its default value.

Fix lib/src/core/routable.dart. (-5.48 points)

Analysis of lib/src/core/routable.dart reported 1 warning, 1 hint:

line 98 col 8: Parameters can't override default values, this method overrides 'Router.addRoute' where 'middleware' has a different value.

line 98 col 43: Use = to separate a named parameter from its default value.

Fix additional 9 files with analysis or formatting issues. (-20.25 points)

Additional issues in the following files:

  • lib/src/core/metadata.dart (11 hints)
  • lib/src/http2/angel_http2.dart (6 hints)
  • lib/src/core/injection.dart (5 hints)
  • lib/src/core/response_context.dart (5 hints)
  • lib/src/http/angel_http.dart (5 hints)
  • lib/src/core/map_service.dart (4 hints)
  • lib/src/core/request_context.dart (2 hints)
  • lib/src/http2/http2_response_context.dart (2 hints)
  • lib/src/http/http_response_context.dart (1 hint)

Maintenance suggestions

Package is pre-release. (-5 points)

Pre-release versions should be used with caution; their API can change in breaking ways.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev <3.0.0
angel_container ^1.0.0-alpha 1.0.0
angel_http_exception ^1.0.0 1.1.0
angel_model ^1.0.0 1.0.2
angel_route ^3.0.0 3.0.5
charcode ^1.0.0 1.1.2
combinator ^1.0.0 1.1.0
file ^5.0.0 5.0.7
http2 ^1.0.0 1.0.0
http_parser ^3.0.0 3.1.3
http_server ^0.9.0 0.9.8+1
logging >=0.11.3 <1.0.0 0.11.3+2
matcher ^0.12.0 0.12.5
merge_map ^1.0.0 1.0.2
meta ^1.0.0 1.1.7
mime ^0.9.3 0.9.6+2
mock_request ^1.0.0 1.0.5
path ^1.0.0 1.6.2
quiver_hashcode ^2.0.0 2.0.0
stack_trace ^1.0.0 1.9.3
tuple ^1.0.0 1.0.2
uuid ^2.0.0-rc.1 2.0.1
Transitive dependencies
code_buffer 1.0.1
collection 1.14.11
convert 2.1.1
crypto 2.0.6
dart2_constant 1.0.2+dart2
intl 0.15.8
quiver 2.0.2
source_span 1.5.5
string_scanner 1.0.4
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
http ^0.11.3
io ^0.3.0
test ^1.0.0