Skip to content

Support typed path parameters in route paths#2912

Open
Harshal96 wants to merge 4 commits into
vert-x3:masterfrom
Harshal96:feature/typed-path-params
Open

Support typed path parameters in route paths#2912
Harshal96 wants to merge 4 commits into
vert-x3:masterfrom
Harshal96:feature/typed-path-params

Conversation

@Harshal96

Copy link
Copy Markdown

Motivation:

Closes #2860

This PR adds the syntax proposed in the issue:

router.get("/users/:id:int").handler(ctx -> {
  int id = Integer.parseInt(ctx.pathParam("id")); // guaranteed to be an integer
});

@vietj vietj added this to the 5.2.0 milestone Jun 10, 2026
Comment thread vertx-web/src/main/java/io/vertx/ext/web/impl/RouteImpl.java Outdated
Comment thread vertx-web/src/main/java/io/vertx/ext/web/impl/RouteImpl.java Outdated
@vietj

vietj commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

@Harshal96 we need a test that uses an invalid type, e.g. /id:foo

@Harshal96

Copy link
Copy Markdown
Author

@vietj have accommodated the feedback

Comment thread vertx-web/src/main/asciidoc/index.adoc Outdated
Comment thread vertx-web/src/main/asciidoc/index.adoc Outdated
Comment thread vertx-web/src/main/asciidoc/index.adoc Outdated
@Harshal96

Copy link
Copy Markdown
Author

@vietj good for another review?

@vietj vietj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after looking at this again, the syntax to declare a type is ambiguous with a second parameter.

we can follow the same syntax as SQL query with :: instead of :.

so example should be

router.route("/blah/:id::integer").handler(rc -> rc.response().setStatusMessage(rc.pathParam("id")).end());

@Harshal96

Copy link
Copy Markdown
Author

@vietj updated : -> ::

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

vertx-web - Make it easy to declare uri template parameter type should be int

3 participants