0
Embla on GitHub

Easy-to-use server side framework for Dart

Nothing complicated.

get embla => [

Instead of a "main" function, Embla requires an "embla" getter in the script, that returns a list of Bootstrappers.

  new HttpBootstrapper(

Bootstrappers are plugins to the application. Out of the box, Embla comes with an HTTP specific one.

    pipeline: pipe(

The HTTP bootstrapper has a "pipeline" parameter, representing the HTTP pipeline.



      // Middleware
      RemoveTrailingSlashMiddleware,

This middleware redirects all requests that have a trailing slash (like /about/) to the corresponding url without the slash (/about).

      LoggerMiddleware,

This middleware logs all requests to the terminal along with some statistics and a timestamp.

      ErrorHandlerMiddleware,

This middleware handles all errors thrown in the route handlers or subsequent middleware. You can also add handlers for specific types of exceptions, like HttpNotFoundException.

      InputParserMiddleware,

This middleware parses the body of the requests and saves it to an "Input" object, which can then be injected in the route handlers, by the Dependency Injection system.



      // Routes
      Route.all('auth/*',

A route is a middleware that creates a fork in the pipeline. All requests that start with "/auth" now flows through this new pipeline. Only if it doesn't find any matching handler within, it will be passed on the the "Hello, world!" handler below.

        AuthController

Controllers, just like routes, are middleware too. They contain collections of routes, which they map to methods with special annotations.

Since this "AuthController" is routed to the "auth/*" namespace, all controller routes will be relative to that prefix.

      ),

      Route.get('about', () => 'About page!'),

Routes can specify the method it requires. This one only matches GET requests.

Routes that doesn't end with an asterisk requires the URL to match exactly. Requests to the URL "about/something-else" would fall through to the "Hello, world!" handler.



      // Fallback handler
      () => 'Hello, world!'

A simple pipeline containing a single handler that will respond to every request—Hello world!
All requests that don't get a response from middleware above this line will fall through to this handler.

Add some middleware
Add some middleware
Add some routes
Add some routes
    )
  )
];
Get started!