ruta 0.1.16
ruta: ^0.1.16 copied to clipboard
A lightweight and flexible backend framework for Dart, inspired by dart_frog.
Ruta Framework #
Ruta is a lightweight and flexible backend framework for Dart, inspired by dart_frog. It provides a simple and intuitive way to build RESTful APIs and web servers with a focus on developer productivity and performance.
Features #
- Simple Routing: Define routes with ease using a clean and expressive syntax.
- Middleware Support: Add middleware to handle cross-cutting concerns like logging, authentication, and more.
- Lightweight: Minimal overhead for fast and efficient server-side applications.
- Dart-Powered: Leverage the power of Dart for type safety and modern language features.
Getting Started #
-
Add
ruta
to yourpubspec.yaml
:dependencies: ruta: ^0.1.9 getIt: ^8.0.3 injectable: ^2.3.2 dev_dependencies: build_runner: ^2.4.13 injectable_generator: ^2.6.2 ruta_generator: ^0.1.8
-
Create a route using Ruta's annotation-based system with dependency injection:
import 'package:injectable/injectable.dart'; import 'package:ruta/annotations.dart'; import 'package:ruta/ruta.dart'; @module abstract class DependencyContainer { @Named('apiVersion') String get apiVersion => '0.0.1'; } @rutaRoute class InfoRoute extends Route { InfoRoute({ @Named('apiVersion') required this.apiVersion, }); final String apiVersion; Endpoint get index { return Endpoint.get( path: '', handler: (req) { return Response.json( body: {'apiVersion': apiVersion}, ); }, ); } }
-
Activate Ruta CLI:
dart pub global activate ruta_cli
-
Generate code for server using ruta_cli:
ruta build
or use build_runner
dart run build_runner build --delete-conflicting-outputs
-
Run your server using the Ruta CLI:
ruta run
Your server will start, and you can test the endpoint at http://localhost:8080/info