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

URL queries #146

Merged
merged 3 commits into from
Jan 5, 2022
Merged

URL queries #146

merged 3 commits into from
Jan 5, 2022

Conversation

patchgamestudio
Copy link
Contributor

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 name queries.

Docs and tests have been updated to reflect changes.

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.
@netlify
Copy link

netlify bot commented Jan 3, 2022

✔️ 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
Copy link
Member

@sansyrox sansyrox Jan 4, 2022

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?

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Member

@sansyrox sansyrox left a 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.

Comment on lines +238 to +247
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);
}
}

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Member

@sansyrox sansyrox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! :D

@sansyrox sansyrox merged commit ba4aae8 into sparckles:main Jan 5, 2022
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

Successfully merging this pull request may close these issues.

None yet

2 participants