| Crates.io | netron_axum_server_hook |
| lib.rs | netron_axum_server_hook |
| version | 0.3.0 |
| created_at | 2025-11-26 10:36:07.607546+00 |
| updated_at | 2025-11-26 10:36:07.607546+00 |
| description | A procedural macro that helps to auto register axum routes |
| homepage | |
| repository | https://github.com/netrondev/netron |
| max_upload_size | |
| id | 1951226 |
| size | 33,242 |
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(())
}
# curl -sL localhost:4000/api/hello
"world!"
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