Skip to main content

daravel 1.13.0 copy "daravel: ^1.13.0" to clipboard
daravel: ^1.13.0 copied to clipboard

A Laravel-inspired, AOT-native backend framework for Dart with routing, validation, an ORM, auth, queues and Laravel-compatible wire formats.

example/main.dart

import 'dart:io';

import 'package:daravel/daravel.dart';

/// A minimal Daravel application: one JSON route and validation, driven
/// in-process with `Application.handle` (no socket needed).
///
/// In a real project, `dartisan new` creates `bootstrap/app.dart` and
/// `bin/server.dart` serves it with `Application.serveWith(createApp)`.
Future<void> main() async {
  final app = Application.configure(basePath: Directory.systemTemp.path)
      .withEnv(const {'APP_ENV': 'local', 'DB_DATABASE': ':memory:'})
      .withRouting(
        apiPrefix: '/api',
        api: (router) {
          router.get('/ping', (_) => {'message': 'pong'});
          router.post('/greet', (request) async {
            final data = await request.validate({
              'name': 'required|string|max:40',
            });
            return {'greeting': 'Hello, ${data.string('name')}!'};
          });
        },
      )
      .create();
  await app.boot();

  final ping = await app.handle(Request.fake(path: '/api/ping'));
  print('${ping.status} ${await ping.bodyText()}');

  final invalid = await app.handle(
    Request.fake(method: 'POST', path: '/api/greet', json: const {}),
  );
  print('${invalid.status} ${await invalid.bodyText()}');

  await app.shutdown();
}
0
likes
160
points
322
downloads

Documentation

Documentation
API reference

Publisher

verified publisherframework.daravel.dev

Weekly Downloads

A Laravel-inspired, AOT-native backend framework for Dart with routing, validation, an ORM, auth, queues and Laravel-compatible wire formats.

Homepage
Repository (GitHub)
View/report issues
Contributing

Topics

#server #backend #framework #http #orm

License

MIT (license)

Dependencies

collection, crypto, cryptography, ffi, markdown, meta, mime, path, postgres, sqlite3, timezone, uuid

More

Packages that depend on daravel