Params Request: get per name #236
-
First, let me congratulate you for such a powerful framwork, but I have a problem when I create a route with parameters, I think that the right thing (as in other frameworks: expressjs, fastify) would be for an object to return and not do app.get('/candy/:kind', (res, req) => {
/* Parameters */
res.end('So you want candy? Have some ' + req.getParameter(0) + '!');
}) Should be: app.get('/candy/:kind', (res, req) => {
/* Parameters */
res.end('So you want candy? Have some ' + req.params['kind'] + '!');
}) Or in any case: app.get('/candy/:kind', (res, req) => {
/* Parameters */
res.end('So you want candy? Have some ' + req.getParameterName('kind') + '!');
}) The latter to not conflict with the current API. |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 8 replies
-
Lookup by index is what this library does. It is not that hard to keep track of what is what, and mixup can happen either way. |
Beta Was this translation helpful? Give feedback.
-
I say it because it is better to call him by his name than by his position |
Beta Was this translation helpful? Give feedback.
-
@alexhultman Consider it please, many of us will thank you, so you will have more people from Express who migrate to uWebSockets.js. |
Beta Was this translation helpful? Give feedback.
-
I have considered it. Lookup by index is free, lookup by name requires building some kind of hash map or linearly searching the URL multiple times. It is really not that complex to write let kind = req.getParameter(0) and then use kind as type safe variable. That mapping is free. |
Beta Was this translation helpful? Give feedback.
-
Yes it is easy to make own solution. This is mine:
|
Beta Was this translation helpful? Give feedback.
I have considered it. Lookup by index is free, lookup by name requires building some kind of hash map or linearly searching the URL multiple times. It is really not that complex to write
let kind = req.getParameter(0) and then use kind as type safe variable. That mapping is free.