redstone-dart / redstone

A metadata driven microframework for Dart.
http://redstone-dart.github.io/redstone
MIT License
342 stars 42 forks source link

How to use manager.addRouteWrapper? #89

Closed austincummings closed 9 years ago

austincummings commented 9 years ago

Hi @luizmineo,

I'm trying to use addRouteWrapper to create shorthand route declarations. Ideally I would like to use them like so...

@Get('/user')
User getUser() => _user;

Right now I just have this and I can not get any further. No route is created, surely I'm using this wrong. Any help would be greatly appreciated.

class Get {
    final String url;

    const Get(String this.url);
}

....

@Get("/test")
String testGet() {
    return '';
}

....

web.addPlugin((manager) {
    manager.addRouteWrapper(Get, (myAnnotation, pathSegments, injector, request, route) {
        print(myAnnotation);
        print(pathSegments);
        print(injector);
        print(request);
        print(route);
        return route(pathSegments, injector, request);
    });
});
luizmineo commented 9 years ago

You can't use a wrapper to create a route, it can only be applied to existing routes.

It's possible to search for functions annotated with your custom annotation, and create routes for them, although, you'll need to implement the parameter binding yourself.