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

Dart 1 only

A friendly web server transport layer for server side Dart apps

Changelog #

0.3.0 #

  • Added an --isolates flag, that allows the application to be multiplexed over multiple isolates. It defaults to 1.
> embla start --isolates 3
> embla start -i 3
> dart bin/server.dart -i 3

0.2.2 #

  • Fixed a bug where routing stars didn't require a slash to follow:
Route.get('path/*')
// no longer matches "/path_and_more"
// only "/path/and_more"
  • Fixed a bug where the UrlEncodedInputParser didn't actually decode the URL component:
key=value -> { 'key': 'value' }

// before 0.2.2
key=value%20with%20spaces -> { 'key': 'value%20with%20spaces' }
// after 0.2.2
key=value%20with%20spaces -> { 'key': 'value with spaces' }

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
30
pub points
0%
popularity

Publisher

unverified uploader

A friendly web server transport layer for server side Dart apps

Homepage

License

MIT (LICENSE)

Dependencies

shelf, shelf_static, stack_trace, watcher

More

Packages that depend on embla