http-rs / surf

Fast and friendly HTTP client framework for async Rust
https://docs.rs/surf
Apache License 2.0
1.45k stars 119 forks source link

Client -> RequestBuilder with a user-provided Method? #260

Closed aldanor closed 3 years ago

aldanor commented 3 years ago

It looks like this has been oversought. How do you create a RequestBuilder from a Client (which may have a base url and the corresponding url logic) if you have a Method and an url?

Maybe something like client.request(Method::Get, "foo") would be worthwhile adding?

(There's Client::send(), but perhaps there might be a more ergonomic option)

jbr commented 3 years ago

I've run into this as well and think that we can do better than client.send(Request::new(Method::Get, Url::parse("http://_").unwrap()).await?

aldanor commented 3 years ago

@jbr Moreover, I think that's not the same thing because of the whole base_url logic? (this part is completely unobvious, as a matter of fact)

jbr commented 3 years ago

That's true — it diverges if you're using base_url

Fishrock123 commented 3 years ago

I agree, this appears to be an oversight.

I'd take a pr for Client::request(&self, Method, Url) -> RequestBuilder.

Fishrock123 commented 3 years ago

Note: once the change described in https://github.com/http-rs/surf/issues/237 is made, this would probably change to:

Client::request(&self, Method) -> RequestBuilder

Since Client would normally have a base_url set already. If this form was still needed a request_with_url could be introduced, although I doubt that would be necessary.

utsavm9 commented 3 years ago

Hey! Let me know if #308 is the intended function we want to add.

Fishrock123 commented 3 years ago

Done in #308