shelf_router_macro 0.0.0-dev.4 copy "shelf_router_macro: ^0.0.0-dev.4" to clipboard
shelf_router_macro: ^0.0.0-dev.4 copied to clipboard

Experimental Dart package that is a thin wrapper for shelf_router using macros

shelf_router_macro #

build pub package License: MIT

🚧 Experimental support for shelf_router using macros.

🌟 Features #

  • ✨ Route declarations
  • ✨ Route parameters
  • ✨ Lightweight - no additional dependencies beyond shelf_router
  • πŸ–ŠοΈ In Progress Intuitive - custom return types
  • πŸ–ŠοΈ In Progress Minimalistic - no need to specify Request/Response, just return response body

πŸ§‘β€πŸ’» Example #

import 'package:data_class_macro/data_class_macro.dart';

@Controller()
class GreetingController {
  @Get('/<name>')
  Response greetingByName(Request request, String name) {
    return Response.ok('Hello, $name!');
  }

  // you can also omit Request/Response
  // WARNING: only String return type is supported for now
  @Get('/wave')
  String wave() {
    return '_o/';
  }
}

void main() async {
  final controller = GreetingController();
  unawaited(
    serve(controller.router, 'localhost', 8080),
  );
  print('βœ… Server listening on http://localhost:8080/');

  print('πŸ” Testing...');
  (await (await HttpClient().get('localhost', 8080, '/eeqk')).close())
      .transform(utf8.decoder)
      .listen(print); // Hello, eeqk!
}

πŸš€ Quick Start #

Important

This package requires Dart SDK >= 3.5.0-164.0.dev

  1. Download Dart from dev or master channel

    $ flutter channel master
    
  2. Add package:shelf_router_macro to your pubspec.yaml

    $ dart pub add shelf_router_macro
    
  3. Enable experimental macros in analysis_options.yaml

    analyzer:
      enable-experiment:
        - macros
    
  4. Use annotations provided by this library (see above example).

  5. Run it

    $ dart --enable-experiment=macros run lib/main.dart
    
1
likes
0
points
8
downloads

Publisher

verified publishereeqk.codes

Weekly Downloads

Experimental Dart package that is a thin wrapper for shelf_router using macros

Repository (GitHub)
View/report issues

Topics

#server #shelf #macros

License

unknown (license)

Dependencies

collection, macros, meta, shelf, shelf_router

More

Packages that depend on shelf_router_macro