5 unstable releases
| 0.3.0 | Nov 26, 2025 |
|---|---|
| 0.2.0 | Aug 1, 2025 |
| 0.1.2 | Feb 26, 2025 |
| 0.1.1 | Mar 22, 2023 |
| 0.1.0 | Mar 22, 2023 |
#1463 in Parser implementations
45KB
720 lines
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
Dependencies
~100MB
~2M SLoC