reqwest icon indicating copy to clipboard operation
reqwest copied to clipboard

Relative URL without base should be allowed for WASM target

Open segfault87 opened this issue 3 years ago • 2 comments

I am trying to use reqwest for creating in-browser request for my WASM application.

But reqwest only accepts full URL for making requests. My web app and resource I'm trying to get is on the same host. When I try to create relative URL, it returns ParseError::RelativeUrlWithoutBase instead.

I think this limitation makes reqwest not suitable for web frontend development for some cases. reqwest should accept relative URLs for WASM target.

segfault87 avatar Jan 10 '22 04:01 segfault87

Seems like it is an inherent limitation on rust-url crate. Any way to circumvent?

segfault87 avatar Jan 10 '22 05:01 segfault87

The same problem with me! I use window.location.origin to walk around this error.

pub fn base_url() -> String {
    web_sys::window().unwrap().location().origin().unwrap()
}
let url = base_url() + "the relative path".

Mng12345 avatar Jun 28 '22 13:06 Mng12345