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.

Cannot get params from context

See original GitHub issue

It seems that get method does not handle the parameter from the url if I write that route router.get('/book/:id', (context) => { // route action }) nothing is happening. I removed the ‘/:id’ part of the string and that seems to be the issue here … but how to indicate parameters if not that way ?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
Waxoussoucommented, May 25, 2020

Hi @Waxoussou 😄

Your error handler middleware should be placed after declaring the routes. The error will happen in one of the routes and then it will be passed to the handler.

Also, I tested your routes and they seem to be working correctly.

I think that you passing a query param instead of a route param

I’ve tried to send request with curl : ~ curl -X GET http://localhost:5050/api/v1/products/?id=1

Instead of /products/?id=1 it should be /products/1

thanks so much @LauraBeatris !!! indeed , I was passing query params instead ! damn’ … Btw, would you know how to handle query param with oak though ?

About my error handler, it was working well even declared before the routes … I did get errors each time i got one… How can it be ?

0reactions
kitsonkcommented, May 25, 2020

Btw, would you know how to handle query param with oak though

ctx.request.url.searchParams.get("id");

I can see that is getting a bit cumbersome though, and some users would expect to be able to have the params and these “merged”. I want to avoid creating aliases and the like, but I think a helper function that would return the searchParams as a single object optionally merged with the parsed out params would be a good idea… something that would work like this:

const query = queryParams(ctx, { mergeParams: true });
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to pass route params in Context API - Stack Overflow
In the component I'm using, it doesn't work because it doesn't know what the props.match.alpha3Code is. How can I can pass the value?...
Read more >
Context | Android Developers
Get the display this context is associated with. ... context you can access; if the requested application can not be safely loaded into...
Read more >
Routing - Fiber
Route parameters are dynamic elements in the route, which are named or not named segments. This segments that are used to capture the...
Read more >
How To Get Route Path Parameters In Non-Routed Angular ...
Every routed component will get its unique instance of the context component. ... describes value of the route path parameter which doesn't currently...
Read more >
Extracting Request Parameters
If the URI path template variable cannot be cast to the specified type, the Jersey runtime returns an HTTP 400 Bad Request error...
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