Question: Nice/good way of extracting query parameters from URI?
renannprado opened this issue · 2 comments
renannprado commented
assiming this is the route:
builder.get(r"/api/test?.*", test_handler);
is this the best way to extract query parameters?
pub fn test_handler(req: Request, res: Response, c: Captures) {
let caps = c.unwrap();
let url_params = &caps[0].replace("/api/test?", "");
let parsed_params: Vec<&str> = url_params.split('&').collect();
}
gsquire commented
I think you want to use a capturing group in order to extract them easier. Is your goal to use query parameters here? You may be better off using a crate like url if so.
renannprado commented
The library that you mentioned unfortunately doesn't parse relative URI, which is what I need.
Of course I could prepend a fake base like http://fake/....
, but I tried to find a less hacky solution.
The below library seems to be a better option, however still it's not possible to extract values from the query string by name. This has to be implemented by yourself :( .
https://docs.rs/http/0.2.0/http/
Thanks!