question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature Request] Support url parameters without router positions

See original GitHub issue

I’m submitting a…


[ ] Regression 
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

It’s only possible to use parameters if they’re route parameters.

For example, to access name and age, a route must be set up as:

:name/:age

Expected behavior

It should be possible to use url parameters as well:

E.g. http://localhost:3000/cats?name=gary&age=1.57

Minimal reproduction of the problem with instructions

@Get('cats')
async getByNameAndAge(@Param('name') name: string, @Param('age'): number): Promise<object> {
   return Promise.resolve({"name": name, "age": age, "success": true})
}

What is the motivation / use case for changing the behavior?

Url parameters being parsed in any order is better for long lists of parameters and the potential for optional parameters compared to positional route parameters.

Environment


Nest version: 4.6.6

 

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
kamilmysliwieccommented, May 19, 2018

I’ll provide an example in the docs.

1reaction
chanlitocommented, May 18, 2018

@natejgardner you can use @Query('name') or @Query('age') as well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Get current route without parameters - Stack Overflow
To get current route without query parameters, you can use below mentioned single line: this.router.url.split('?')[0].
Read more >
Using parameters in routes - Drupal Wiki
Parameters can be used to pass dynamic values from the URI to the controller.
Read more >
How to Get URL Parameters with JavaScript - SitePoint
Learn how to parse query string parameters and get their values in JavaScript. Use the results for tracking referrals, autocomplete, ...
Read more >
Routing and URL Parameters | Routing and Navigation | Flow
A navigation target that supports typed parameters passed through the URL should: Implement the HasUrlParameter interface, and. Define the parameter type ...
Read more >
URLSearchParams - Web APIs - MDN Web Docs
Chrome Edge URLSearchParams Full support. Chrome49. Toggle history Full support. Edge... @@iterator Full support. Chrome49. Toggle history Full support. Edge... URLSearchParams() constructor Full support. Chrome49. Toggle...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found