-
-
Notifications
You must be signed in to change notification settings - Fork 210
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
URL queries #146
URL queries #146
Conversation
The data can be accessed similar to POST requests, using "queries" instead of "params".
Update unit tests to verify URL form queries work correctly.
Fix query return value when only a keyword is passed for the key-value pair.
✔️ Deploy Preview for robyn canceled. 🔨 Explore the source changes: 77e39c7 🔍 Inspect the deploy log: https://app.netlify.com/sites/robyn/deploys/61d32b5534857e0007e4e93c |
@@ -1,2 +1,3 @@ | |||
flake8==4.0.1 | |||
black==21.12b0 | |||
websockets==10.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you add this in the dev requirements?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While trying to build and test robyn, I ran into an issue where the websockets
dependency hadn't been met. I looked around, and it gets called in robyn/integration_tests/test_web_sockets.py
. Since it isn't necessary for normal operation, it seemed more appropriate to add it to dev-requirements.txt
. I suppose it isn't really necessary for this to be included for the feature, but I felt like it was worth slipping it in to help with long term CI/CD.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that makes sense. Thank you! :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @patchgamestudio ,
Thank you for your contribution 😄
I have a few inline comments, the PR looks good otherwise.
let mut queries = HashMap::new(); | ||
|
||
if req.query_string().len() > 0 { | ||
let split = req.query_string().split("&"); | ||
for s in split { | ||
let params = s.split_once("=").unwrap_or((s, "")); | ||
queries.insert(params.0, params.1); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want the queries hashmap to be available in every HTTP request or just the GET requests methods?
I usually use this kind of params in GET requests only. But I am not sure about the standard of WEB requests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I think it's generally only necessary for GET requests. That being said, this project doesn't exist for just me. I expect developers will want to use features like this in unorthodox ways. There didn't seem to be a good reason to restrict queries solely to GET requests, so I left it open to all types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I expect developers will want to use features like this in unorthodox ways
Absolutely! Robyn is based on making unorthodox tradeoffs for better performance. I love it. :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! :D
Description
This PR adds support for URL form queries, which do not match REST-like patterns such as
/path/<id>
. The Rust side already has access to query strings for requests to paths such as/path?foo=bar
. This data is made available on the Python side as a dict object similar to headers under the key namequeries
.Docs and tests have been updated to reflect changes.