/laska

Microframework for Dart inspired by Bottle and Echo

Primary LanguageDartMIT LicenseMIT

Laska

Laska is a server-side microframework for Dart, which aims to be a fast, simple and lightweight.

  • Routing: Requests to function-call mapping with support for clean and dynamic URLs.
  • Middlewares: Middlwares allow developers to modify request before it's being processed.
  • Isolates: Laska uses Isolates to secure request processing.

Example: "Hello world" in a Laska

import 'package:laska/laska.dart';

void main() async {
  final laska = Laska();

  laska.GET('/hello/:name',
      (context) async => await context.Text("Hello ${context.param('name')}!"));

  await run(laska);
}

Run this script via dart run hello_world.dart, then point your browser to http://localhost:3789/hello/world. That’s it.

Current state

Active development, not for production use.

Full Example

import 'dart:io';

import 'package:laska/laska.dart';

void main() async {
  // Create new Laska object
  final laska = Laska();

  // Set global BasicAuth middleware 
  laska.Use(BasicAuth('laska', 'ermine', realm: 'Access to private zone'));

  laska.GET('/users/:userId', getUserById);
  laska.POST('/users/', createUser);

  // Start server
  await run(laska);
}

void getUserById(Context context) async {
  await context.HTML('User: <b>${context.params['userId']}</b>');
}

void createUser(Context context) async {
  await context.JSON({'status': 'created'}, statusCode: HttpStatus.created);
}

Routing

Laska uses a powerful routing engine to find the right callback for each request. it's based on Trie data structure which let it be very performant.

License

MIT