【Axum】发送 POST 请求
环境
- Time 2022-01-16
- Rust 1.58.0
- Axum 0.4.4
概念
参考:https://docs.rs/axum/latest/axum/index.html
示例
main.rs
use axum::{routing::post, Router};
use std::net::SocketAddr;
#[tokio::main]
async fn main() {
let app = Router::new().route("/", post(home));
let addr = SocketAddr::from(([127, 0, 0, 1], 4444));
println!("listening on {addr}");
axum::Server::bind(&addr)
.serve(app.into_make_service())
.await
.unwrap();
}
async fn home(name: String) -> String {
format!("hello {name}")
}
总结
使用 axum 发送 POST 请求,并接收和返回数据。