Thanks for the feedback. I don't have a problem with a resource being
accessible from multiple routes. I can put redirect logic in the
application code if I want true one-to-one mapping. I like beautiful and
simple URLs (github comes to mind) even at the cost of a little ambiguity
(github.com/blog is not a user named blog, but github.com/github is a user).
I currently do my validation/filtering using regular expressions like you
mention:
if (value.match(/^\d+$/)) { ... }
but my goal here is simply to add some sugar so I don't have to write that
logic over and over. String of course is the default and implied. I'd like
to expose the namedType -> regex map to userland so an application can add
some helpers for various param type it often uses besides [int] and [hex].
Typecasting might be a bonus in the case of [int] or maybe even [date].
On Tuesday, November 5, 2013 7:22:56 AM UTC-8, Alex Kocharin wrote:
>
>
> This is how it's done in express.js:
>
> ```
> app.param('id', function(req, res, next, value, name) {
> if (value.match(/^\d+$/)) {
> next()
> } else {
> next('route')
> }
> })
>
> app.get('/users/:id', function(req, res, id) { ... })
> ```
>
> Do something similar. There is no need to add anything to a route, because
> the name of the param should already imply the type.
>
> If you write "name", it is string, right? Anybody who reads the code will
> understand that without any explicit "[string]" garbage attached to it.
>
>
> On Monday, November 4, 2013 10:37:28 PM UTC+4, Simon wrote:
>>
>> In my URL routing (express/sinatra-style), I'd like to enable optional
>> parameter "filters" (like int, hex) while keeping syntax familiar and
>> simple. The typical syntax for a routing library might look something like:
>>
>> app.get('/users/:id', function(req, res, id) { ... });
>>
>> I'd like to introduce a syntax for catching only numeric ids so we could
>> have another route for users by name for instance.
>>
>> app.get('/users/:id[int]', function(req, res, id) { ... });
>> app.get('/users/:name', function(req, res, username) { ... });
>>
>> There doesn't seem to be a convention for this, so I've been considering
>> the following:
>>
>> '/users/:id[int]'
>> '/users/:id(int)'
>> '/users/:id:int'
>> '/users/:id=int'
>>
>> Any feedback on what's a good way to go that will be simple and obvious
>> to someone reading the code? If a well-known library is already doing
>> something like this I'll go with whatever the community is using. Votes
>> welcome..
>>
>>
>>
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.