In url crate, how do I construct query params without the library encoding them to urlencoded format?

⚓ Rust    📅 2025-07-26    👤 surdeus    👁️ 6      

surdeus

I am using the url crate. I parse a string into Url and then I want to add query parameters to this URL.
I am trying to do it like this,


        let query_params = [
            ("client_id", self.client_id.as_str()),
            ("scope", "read,read_all,profile:read_all,profile:write,profile:write,activity:read,activity:read_all,activity:write"),
            ("redirect_uri", self.redirect_uri.as_str()),
            ("approval_prompt", "force"),
            ("response_type", "code")
        ];

        for (p, q) in query_params {
            url.query_pairs_mut().append_pair(p, q);
        }

but the url crate is encoding the query parameters into urlencode format so the url looks like this,

https://www.strava.com/oauth/authorize?client_id=169855&scope=read%2Cread_all%2Cprofile%3Aread_all%2Cprofile%3Awrite%2Cprofile%3Awrite%2Cactivity%3Aread%2Cactivity%3Aread_all%2Cactivity%3Awrite&redirect_uri=https%3A%2F%2Fstrava.ishanjain.me%2Fauth_callback&approval_prompt=force&response_type=code

Is there a nicer way to do this without going back to creating the query parameter string myself and setting it with set_query ?

I am just venting a little bit but the url crate has such a horrible API I dread every single time I have to do any thing with it.

1 post - 1 participant

Read full topic

🏷️ Rust_feed