embla 0.2.1 copy "embla: ^0.2.1" to clipboard
embla: ^0.2.1 copied to clipboard

outdatedDart 1 only

A friendly web server transport layer for server side Dart apps

Changelog #

0.2.1 #

Adds a new ForwarderMiddleware that acts as a proxy to another server.

Also adds a PubMiddleware which combines the StaticFilesMiddleware and the new ForwarderMiddleware to forward to Pub serve in dev mode, and to the build directory in production mode.

pipe(
  // Middleware preceding the PubMiddleware will now be available on the same server
  // that deals with transformers and stuff!
  Route.get('special-endpoint', () => 'Hello from server!'),
  PubMiddleware  
)
> pub serve
# In another tab
> APP_ENV=development embla start

Pre 0.2 #

An empty Embla app is an empty getter called embla in the script, with an export statement.

export 'package:embla/bootstrap.dart';
get embla => [];

The getter should return a List<Bootstrapper>.

import 'package:embla/application.dart';
export 'package:embla/bootstrap.dart';

List<Bootstrapper> get embla => [];

Bootstrappers attach listeners to application lifetime hooks.

import 'package:embla/application.dart';
export 'package:embla/bootstrap.dart';

get embla => [
  new MyBootstrapper()
];

class MyBootstrapper extends Bootstrapper {
  @Hook.init
  init() {
    print('Starting the application up!');
  }

  @Hook.exit
  exit() {
    print('Shutting the application down!');
  }
}

Methods in a bootstrapper can use Dependency Injection to inject classes. Since Embla uses a stateless IoC container, adding bindings to the container returns a new instance. To push the new bindings into the application, the bootstrappers can return the new container in any of its methods.

The container itself is available from the Bootstrapper superclass.

class AddsBindingsBootstrapper extends Bootstrapper {
  @Hook.bindings
  bindings() {
    return container.bind(SomeAbstractClass, to: SomeConcreteClass);
  }
}

The hooks, as well as the container, is documented in doc comments.

HTTP Pipeline

The basic Embla library comes with an HttpBootstrapper, which takes some configuration as named parameters. One of which is the pipeline parameter, expecting a Pipeline.

The pipe helper creates a Pipeline from one or more Middleware:

import 'package:embla/http.dart';
export 'package:embla/bootstrap.dart';

get embla => [
  new HttpBootstrapper(
    pipeline: pipe(
      SomeMiddleware
    )
  )
];

There are some middleware that comes out-of-the-box, for routing as well as for some common tasks like removing trailing slashes from URLs, parsing the request body, or handling errors thrown in the pipeline.

0
likes
0
pub points
0%
popularity

Publisher

unverified uploader

A friendly web server transport layer for server side Dart apps

Homepage

License

unknown (LICENSE)

Dependencies

shelf, shelf_static, stack_trace, watcher

More

Packages that depend on embla