dart-lang / shelf

Web server middleware for Dart
https://pub.dev/packages/shelf
BSD 3-Clause "New" or "Revised" License
920 stars 124 forks source link

Router handler with params and Pipeline for middleware #318

Open acorn371 opened 1 year ago

acorn371 commented 1 year ago

Hi, I have a router like the following, using a Pipeline for an authorization middleware.

    router.get( '/user/<user_id>', Pipeline()
            .addMiddleware(authorize(authorization))
            .addHandler(_getCurrentUserHandler));

I see I could use something like:

router.get('/user/<user_id>', (Request request, String user_id) {
???
});

But I don't know how to use my pipeline with the second handler form, the one using the param user_id because method addHandler get and return an Handler of the form FutureOr<Response> Function(Request request); Any idea ? Many thanks

ikaem commented 1 month ago

@acorn371 , would something like this help (my example):

    playersRouter.get(
      "/<id>",
      Pipeline().addHandler((request) =>
          getPlayerController.call(request, request.params["id"]!)),
    );