Skip to content

Commit

Permalink
Moved example to standalone file
Browse files Browse the repository at this point in the history
  • Loading branch information
MassiminoilTrace committed Oct 26, 2023
1 parent df2982a commit 76f9264
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
8 changes: 3 additions & 5 deletions docs-src/0.4/en/reference/fullstack/server_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,12 @@ In the server code, first you have to set the network address where the server w
Afterwards, you have to register the types declared in the server function macros into the axum server.
For instance, consider this server function:
```rust
#[server(GetServerData)]
async fn get_server_data() -> Result<String, ServerFnError> {
Ok("Hello from the server!".to_string())
}
{{#include src/doc_examples/server_function_desktop_client.rs:server_function}}
```

The `GetServerData` type has to be registered in the axum server, which will add the corresponding route to the server.
```rust
let _ = GetServerData::register_explicit();
{{#include src/doc_examples/server_function_desktop_client.rs:function_registration}}
```

Finally, the server is started and it begins serving data.
31 changes: 31 additions & 0 deletions src/doc_examples/server_function_desktop_client.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#![allow(non_snake_case, unused)]
use dioxus_fullstack::prelude::*;

// ANCHOR: server_function
#[server(GetServerData)]
async fn get_server_data() -> Result<String, ServerFnError> {
Ok("Hello from the server!".to_string())
}
// ANCHOR_END: server_function


use axum_desktop::*;
use dioxus_fullstack::prelude::*;

#[tokio::main]
async fn main() {
let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 8080));

// ANCHOR: function_registration
let _ = GetServerData::register_explicit();
// ANCHOR_END: function_registration

axum::Server::bind(&addr)
.serve(
axum::Router::new()
.register_server_fns("")
.into_make_service(),
)
.await
.unwrap();
}

0 comments on commit 76f9264

Please sign in to comment.