2

Is there any possibility to subroute in Aqueduct controller?

router.route("/userApi").link(() => UserController(context));

class UserController extends ResourceController {

@Operation.post("/login")
Future<Response> login(@Bind.body() IdWrap note) async {...}

@Operation.post("/byInnerToken")
Future<Response> login(@Bind.body() IdWrap note) async {...}

post("userApi/login", {"id": "aaa"})
post("userApi/byInnerToken", {"innerToken": "bbb"})
Zdeněk Mlčoch
  • 722
  • 6
  • 17
  • 1
    Why not define separate controllers? router.route("/userApi/login").link(() => UserLoginController(context)); router.route("/userApi/byInnerToken").link(() => UserByInnerTokenController(context)); – UNeverNo Dec 12 '19 at 11:02
  • This is the right solution. I just didn't feel comfortable to have more lines of code than necessary. – Zdeněk Mlčoch Dec 12 '19 at 12:12

1 Answers1

1

Generally, yes, by using path variables.

router.route("/userApi/:type").link(() => UserController(context));

class UserController extends ResourceController {
  @Operation.post('type')
  Future<Response> login(@Bind.path('type') String type, @Bind.body() IdWrap note) async {
    switch (type) {
      case "login": return login(note);
      case "byInnerToken": return withToken(note);
      default: return Response.notFound();
    }
  }
}

There is no ability to pattern match the contents of the path variable.

Joe Conway
  • 1,566
  • 9
  • 8