Skip to content

Instantly share code, notes, and snippets.

@rossabaker
Forked from paulosuzart/gist:413430
Created May 25, 2010 17:55
Show Gist options
  • Save rossabaker/413448 to your computer and use it in GitHub Desktop.
Save rossabaker/413448 to your computer and use it in GitHub Desktop.
// 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>
}
@paulosuzart
Copy link

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(..). :)

@rossabaker
Copy link
Author

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.

@paulosuzart
Copy link

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.

@rossabaker
Copy link
Author

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