dioxus-grpc

Crates.iodioxus-grpc
lib.rsdioxus-grpc
version0.0.4
created_at2025-05-03 18:41:22.644747+00
updated_at2025-05-04 14:54:06.780218+00
descriptionEasy interface for a gRPC client with Dioxus
homepage
repositoryhttps://github.com/tkr-sh/dioxus-grpc
max_upload_size
id1659064
size41,275
tk (tkr-sh)

documentation

https://docs.rs/dioxus-grpc/latest/dioxus_grpc/index.html

README

dioxus-grpc

dioxus-grpc provides a convenient way to use gRPC with Dioxus

Example

fn app() -> Element {
    let req = use_signal(|| HelloRequest { name: String::new() });
    let greeter = use_greeter_service();

    rsx! {
        input {
            value: "{req().name}",
            oninput: move |event| req.write().name = event.value()
        }
        match &*greeter.say_hello(req).read() {
            Some(Ok(resp)) => rsx!{"[{resp.message}] - From server"},
            Some(Err(err)) => rsx!{"Couldn't get the name {err:#?}"},
            None => rsx!{"..."},
        }
    }
}
syntax = "proto3";

package helloworld;

service Greeter {
  rpc SayHello (HelloRequest) returns (HelloReply) {}
}

message HelloRequest {
  string name = 1;
}

message HelloReply {
  string message = 1;
}

A complete example can be found here: ./examples/

How to use ?

By default, this is meant for mobile & desktop. But you can activate it for web with feature = "web"

To use it, you will need to also use tonic-build (and disable the transport feature in case of feature = "web). Therefore, something like:

[build-dependencies]
    dioxus-grpc = "*"
    tonic-build = "0.13"
    # For web:
    # tonic-build = { version = "0.13", default-features = false, features = ["prost"] } 

But, you will also need to import some runtime dependencies:

[dependencies]
    dioxus = { version = "0.6", features = ["mobile"] }
    tonic = "0.13"
    prost = "0.13"
    # For web:
    # tonic = { version = "0.13", default-features = false, features = ["codegen", "prost"] }
    # tonic-web-wasm-client = "0.7"

Once this is done, you can call generate_hooks in ./build.rs. See the examples for more details.

Commit count: 16

cargo fmt