Aqueduct routing behaviour unexpected results

37 Views Asked by At

I am trying to create a backend server with Aqueduct in dart. I am trying to create a resource controller that will deal with account issues.

routing code is like this;

router
        .route("/$apiEntryPointUrl/account/:operation").link(() => AccountController(context, authServer));

When I try to test routers path variables like this;

   @Operation.post("asdf")
  Future<Response> test() async {
    return Response.ok("testsuccess");
  }

  @Operation.post("operation")
  Future<Response> test5() async {
    return Response.ok("bugsuccess");
  }

  @Operation.post("test3")
  Future<Response> test2() async {
    return Response.ok("testsucces3333s");
  }

When I add Operation.post("operation") as path variable, anything I pass into variable goes to this function. If I do a post request to like /account/tes2 it invokes test5() function. Is this normal? Am I missing some basics?

1

There are 1 best solutions below

3
jayjah On

Actually yes, that's normal and intended. If you specify something like this: '/account/:operation' or '/account/:id' in your router then you end up with a kinda wild card, which is in these example cases 'operation' or 'id'. The operator ':' acts as a wild card operation. This means in fact an api call to a route like '/account/tes2' will call the wild card route automatically.