DioxusLabs / DioxusLabs/dioxus
Allow several server URLs
- Dominant language
- Rust
- Stars
- 39.1k
- Forks
- 1.9k
- Avg merge
- 4d 10h
- Merged PRs (30d)
- 4
Description
## Feature Request
In the `main` function of a desktop or mobile app, I can use `dioxus_fullstack::set_server_url` to change the base URL of the RPC system. Looking under the hood, I can see that this function uses a `OnceLock`, and indeed when I try to call it several times it errors.
I would like to be able to change the server URL several times at runtime, even permitting the user to set it, and set several different URLs at the same time for different pages of my app. Think Jellyfin or Mastodon, in which you can enter the URL of the server you want to use.
## Implement Suggestion
I am not sure about the best way to implement this. Maybe the most flexible solution would be to have the RPC procedural macros generate 2 versions of each method in the client, e.g.
```rust
// server
use dioxus::prelude::*;
#[post("/api/echo")]
pub async fn echo(input: String) -> Result {
Ok(input)
}
// client
api::echo("ping").await.unwrap(); // calls `{ROOT_URL}/api/echo` or `/api/echo` if ROOT_URL is not set
api::echo_with_options(RPCOptions { root_url: "https://example.com/dioxus" }, "ping").await.unwrap(); // calls `https://example.com/dioxus/api/echo`
```
This would allow managing the server URL with global context for example.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.