Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncertain how to obtain query parameters #11

Closed
tommaisey opened this issue Oct 30, 2022 · 6 comments
Closed

Uncertain how to obtain query parameters #11

tommaisey opened this issue Oct 30, 2022 · 6 comments
Assignees

Comments

@tommaisey
Copy link

tommaisey commented Oct 30, 2022

I'm probably just making a mistake, but I can't figure out how to match query parameters in a route. The documentation says it's possible, but nothing I've tried works. Mostly I've tried stuff along these lines:

fm.setRoute("/submit%?action=:a", function(r)
    print(r.params.a)
end)

-- When I visit /submit?action=1, this does not match. If I make
-- it optional, i.e. "/submit%?action=(:a)", then it prints false.

Am I missing something? If I am, perhaps I can help improve the documentation once I understand it for the next poor fool like me.

@pkulchenko pkulchenko self-assigned this Oct 30, 2022
@pkulchenko
Copy link
Owner

You can simply access r.params.action without adding it to the route itself. This should work:

fm.setRoute("/submit", function(r)
    print(r.params.a)
end)

Please re-open if it doesn't work for you for some reason.

@tommaisey
Copy link
Author

@pkulchenko No, I'm afraid r.params is an empty table in that case.

I have found that redbean's GetParams() does what I need, though it's a bit outside of the fullmoon idiom.

@tommaisey
Copy link
Author

Ah, I see. So r.params has a metatable, and the parameters are 'materialized' as you ask for them. I was printing it with serpent, looking for the values.

I got it now, thanks!

@pkulchenko
Copy link
Owner

Ah, I see. So r.params has a metatable, and the parameters are 'materialized' as you ask for them.

Correct. I also have on my todo list to add __pairs/__ipairs metamethods to allow all parameters (and headers) to be enumerated.

@tommaisey
Copy link
Author

Thanks for making this framework, it's very powerful and fun to use!

@pkulchenko
Copy link
Owner

That's great to hear; thank you for the feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants