netron

Crates.ionetron
lib.rsnetron
version0.3.0
created_at2023-03-22 15:17:58.773219+00
updated_at2025-11-26 10:39:36.420967+00
descriptionExtract Axum request data within Yew server functions similar to how `leptos_axum` provides extraction helpers for Leptos
homepage
repositoryhttps://github.com/netrondev/netron
max_upload_size
id817224
size160,602
Rouan van der Ende (rvdende)

documentation

README

use netron::prelude::*;

// GET EXAMPLE

#[axumhandler(method = "GET", path = "/api/hello")]
pub async fn hello_world() -> Result<String, AppError> {
    Ok("world!".to_string())
}

// POST EXAMPLE

#[derive(Serialize, Debug, Deserialize, Clone)]
struct FooBar {
    name: String,
    count: u32,
}

#[axumhandler(method = "POST", path = "/api/foo")]
pub async fn test_sending(input: FooBar) -> Result<String, AppError> {
    println!("{:#?}", input);
    Ok("world!".to_string())
}

// MAIN SERVER

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    dotenvy::dotenv().ok();
    server_main().await?;
    Ok(())
}

GET example

# curl -sL localhost:4000/api/hello
"world!"

POST example

curl -X POST http://localhost:4000/api/foo -H "Content-Type: application/json" -d '{"input": {"name": "rouan", "count": 40 }}'

Server console:

2025-11-26T10:34:30.624989Z  INFO http_request{method=POST uri=/api/foo version=HTTP/1.1}: netron::server: API call: POST /api/foo
FooBar {
    name: "rouan",
    count: 40,
}
2025-11-26T10:34:30.625154Z  INFO http_request{method=POST uri=/api/foo version=HTTP/1.1}: netron::server: Response: status=200 OK latency=240.772µs
Commit count: 0

cargo fmt