-
Notifications
You must be signed in to change notification settings - Fork 908
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MatchesParam - Add new "OR" like syntax #4116
Labels
Comments
Thanks a lot for the detailed description, @lucasamoroso. LGTM 👍 |
ikhoon
pushed a commit
that referenced
this issue
Mar 24, 2022
Motivation: Add more flexibility to RoutingPredicate with a new OR syntax Modifications: - RoutingPredicate syntax Result: - Closes #4116. (If this resolves the issue.) - You can now use `@MatchesParam` or `@MatchesHeader` with this new syntax. Example: ```scala @get("/hello") @MatchesParam("with_status!=true || !with_status") def hello(): HttpResponse = HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT, "Hello!") @get("/hello") @MatchesParam("with_status=true || with_status") def helloWithStatus(): HttpResponse = HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT, "Hello! My status is ok") ``` And this should be the result: - `curl http://localhost:8000/hello\?with_status\=true` // "Hello! My status is ok" - `curl http://localhost:8000/hello\?with_status` // "Hello! My status is ok" - `curl http://localhost:8000/hello` // "Hello!" - `curl http://localhost:8000/hello\?with_status\=false` // "Hello!"
heowc
pushed a commit
to heowc/armeria
that referenced
this issue
Mar 25, 2022
Motivation: Add more flexibility to RoutingPredicate with a new OR syntax Modifications: - RoutingPredicate syntax Result: - Closes line#4116. (If this resolves the issue.) - You can now use `@MatchesParam` or `@MatchesHeader` with this new syntax. Example: ```scala @get("/hello") @MatchesParam("with_status!=true || !with_status") def hello(): HttpResponse = HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT, "Hello!") @get("/hello") @MatchesParam("with_status=true || with_status") def helloWithStatus(): HttpResponse = HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT, "Hello! My status is ok") ``` And this should be the result: - `curl http://localhost:8000/hello\?with_status\=true` // "Hello! My status is ok" - `curl http://localhost:8000/hello\?with_status` // "Hello! My status is ok" - `curl http://localhost:8000/hello` // "Hello!" - `curl http://localhost:8000/hello\?with_status\=false` // "Hello!"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi!
Given the following routes:
I'd like to call the
helloWithStatus
route in the following ways:curl http://localhost:8000/hello\?with_status\=true
// This workscurl http://localhost:8000/hello\?with_status
// This doesn't work, returns a NOT_FOUNDThe only way to make this work as expected is with the following code:
This seems to be because
@MatchesParam
is applying a logicalAND
.So, with all that said, @trustin proposed a new syntax like
@MatchesParam("with_status=true || with_status")
to make my first example work. This is the the code that will use this new syntax.And this should be the result:
curl http://localhost:8000/hello\?with_status\=true
// "Hello! My status is ok"curl http://localhost:8000/hello\?with_status
// "Hello! My status is ok"curl http://localhost:8000/hello
// "Hello!"curl http://localhost:8000/hello\?with_status\=false
// "Hello!"Can we add this new syntax?
The text was updated successfully, but these errors were encountered: