Skip to content

Proxy

When you’re dealing with HTTP requests in Rust the most popular library used is reqwest.

[dependencies]
reqwest = "=0.11"

// Unix: myscheme://some/path
// Windows: https://myscheme.localhost/some/path
tauri::Builder::default()
.register_uri_scheme_protocol("myscheme", |app, req| {
// PSEUDO CODE, WILL UPDATE LATER
let response = reqwest::get(format!("https://server/{}", req.path()));
tauri::http::ResponseBuilder::new().body(response.bytes())
});

Using a ServiceWorker in the frontend portion of the project you can reroute any requests sent out from your app to your schema handler.

Why would you do it? Admittedly it’s a fairly niche functionality, but I’ve used it for an extension system in a web capable project. I can set up requests to my remotely running API server, then user the ServiceWorker to reroute those requests to my scheme handler only when running in the Tauri app version, which instead of fetching the extension from the API can check locally for the extensions zip archive to retrieve assets.

References