ruta 0.1.7 copy "ruta: ^0.1.7" to clipboard
ruta: ^0.1.7 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 #

  1. Add ruta to your pubspec.yaml:

    dependencies:
      ruta: ^0.1.0
    dev_dependencies:
      ruta_generator: ^0.1.0
    
  2. Create a route using Ruta's annotation-based system:

    import 'package:ruta/annotations.dart';
    import 'package:ruta/open_api.dart';
    import 'package:ruta/ruta.dart';
       
    @RutaRoute()
    class TestRoute extends Route {
      const TestRoute();
       
      @override
      List<Endpoint> get endpoints => [
            Endpoint(
              path: 'test/<id>',
              method: HttpMethod.get,
              summary: 'Summary of the test endpoint',
              description: 'Some test endpoint description',
              authRequired: true,
              body: [
                Field<String>('password', isRequired: false),
                Field<Map<String, dynamic>>(
                  'items',
                  children: [
                    Field<int>('something'),
                  ],
                ),
              ],
              responses: [
                OpenApiResponse(
                  statusCode: 200,
                  description: 'Provides email',
                  properties: [
                    Field<String>('email', isRequired: false),
                  ],
                ),
              ],
              query: [
                Field<int>('name'),
              ],
              handler: (req) {
                print(434);
                return Response.json(body: {'email': 'example@gmail.com'});
              },
            ),
          ];
       
      @override
      List<Middleware> get middlewares => [
            (Handler handler) {
              return (req) {
                print(req.uri);
                return handler(req);
              };
            },
          ];
    }
    
  3. Activate Ruta CLI:

    dart pub global activate ruta_cli
    
  4. Generate and run your server using the Ruta CLI:

    ruta run
    

Your server will start, and you can test the endpoint at http://localhost:8080/test/123?name=42

2
likes
0
points
125
downloads

Publisher

unverified uploader

Weekly Downloads

A lightweight and flexible backend framework for Dart, inspired by dart_frog.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

collection, get_it, shelf, shelf_cors_headers, shelf_hotreload, shelf_static

More

Packages that depend on ruta