This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// I think this is possible, if we just ignore the names. | |
// | |
// year = :year, month = :month, day = :day | |
get("/date/:year/:month/:day") { (year, month, day) => | |
<ul> | |
<li>Year: { year }</li> | |
<li>Month: { month }</li> | |
<li>Day: { day }</li> | |
</ul> | |
} | |
// But if we ignore the names, bad things happen: | |
// | |
// year = :monht, month = :day, day = :year | |
get("/date/:month/:day/:year") { (year, month, day) => | |
<ul> | |
<li>Year: { year }</li> | |
<li>Month: { month }</li> | |
<li>Day: { day }</li> | |
</ul> | |
} | |
// Something like this might be able to put the parameters, | |
// in any order, but it's not nearly as nice as what you proposed. | |
// | |
// year = :1, month = :2, day = :3 | |
get("/date/:2/:3/:1") { (year, month, day) => | |
<ul> | |
<li>Year: { year }</li> | |
<li>Month: { month }</li> | |
<li>Day: { day }</li> | |
</ul> | |
} | |
// Or, if it's just based on convention... | |
// | |
// year = first :?, month = second :?, day = third :? | |
get("/date/:?/:?/:?") { (year, month, day) => | |
<ul> | |
<li>Year: { year }</li> | |
<li>Month: { month }</li> | |
<li>Day: { day }</li> | |
</ul> | |
} |
We need to be sure that it doesn't conflict with the existing routing syntax. If the closure takes parameters, then that could trigger the by-position mapping -- I think that would work.
Perfect!
:? Does not blur the closure parameter names with request path parameters.
Of course, this way one cannot use params("?") at the same time of passing params to the closure. Nice.
Hope the idea to be useful.
Yes, this is definitely a feature that we would like to add. Thanks for the idea!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think the param names are less important, since the action will perform some operation over the closure parameters. But the params order yes, can be meaningful. Annotation can be expensive and annoying. Can a simply convetion solve this?
The convention could be option. People would decide to explicit the parameters or grab them using params(..). :)