{"id":84914,"date":"2026-07-26T20:41:52","date_gmt":"2026-07-26T12:41:52","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/84914.html"},"modified":"2026-07-26T20:41:52","modified_gmt":"2026-07-26T12:41:52","slug":"axum%ef%bc%9a%e7%94%a8-rust-%e5%86%99-web-%e5%90%8e%e7%ab%af%e7%9a%84%e6%ad%a3%e7%a1%ae%e6%89%93%e5%bc%80%e6%96%b9%e5%bc%8f","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/84914.html","title":{"rendered":"Axum\uff1a\u7528 Rust \u5199 Web \u540e\u7aef\u7684\u6b63\u786e\u6253\u5f00\u65b9\u5f0f"},"content":{"rendered":"<p>\u5982\u679c\u4f60\u8fd8\u5728\u7528 Express \u5199 API&#xff0c;\u6216\u8005\u88ab Actix-web \u7684\u5b8f\u5730\u72f1\u6298\u78e8\u8fc7&#xff0c;\u8fd9\u7bc7\u6587\u7ae0\u5c31\u662f\u4e3a\u4f60\u51c6\u5907\u7684\u3002<\/p>\n<hr \/>\n<h3 id=\"\u4e00axum-\u662f\u4ec0\u4e48\">\u4e00\u3001Axum \u662f\u4ec0\u4e48&#xff1f;<\/h3>\n<p>Axum \u662f Tokio \u56e2\u961f\u5b98\u65b9\u7ef4\u62a4\u7684 Rust Web \u6846\u67b6&#xff0c;\u5b83\u7684\u5b9a\u4f4d\u975e\u5e38\u7cbe\u51c6&#xff1a;\u4e00\u4e2a\u57fa\u4e8e Tower \u4e2d\u95f4\u4ef6\u751f\u6001\u7684\u3001\u7c7b\u578b\u5b89\u5168\u7684\u3001\u6781\u7b80\u4e3b\u4e49 Web \u6846\u67b6\u3002<\/p>\n<p>\u5b83\u4e0d\u662f\u4ec0\u4e48&#034;\u745e\u58eb\u519b\u5200&#034;&#xff0c;\u800c\u662f\u4e00\u628a\u6253\u78e8\u5230\u6781\u81f4\u7684\u65e5\u5f0f\u53a8\u5200\u2014\u2014\u53ea\u505a\u4e00\u4ef6\u4e8b&#xff0c;\u628a\u5b83\u505a\u5230\u6700\u597d&#xff1a;\u5904\u7406 HTTP \u8bf7\u6c42\u4e0e\u54cd\u5e94\u3002<\/p>\n<ul>\n<li>\u5f00\u6e90\u5730\u5740&#xff1a;https:\/\/github.com\/tokio-rs\/axum<\/li>\n<li>\u8bb8\u53ef\u8bc1&#xff1a;MIT&#xff08;\u5b8c\u5168\u81ea\u7531\u5546\u7528&#xff09;<\/li>\n<li>\u6700\u65b0\u7a33\u5b9a\u7248&#xff1a;0.8.x&#xff08;2026 \u5e74 3 \u6708&#xff09;<\/li>\n<li>\u9879\u76ee\u72b6\u6001&#xff1a;Tokio \u5b98\u65b9\u7ef4\u62a4&#xff0c;\u793e\u533a\u6d3b\u8dc3&#xff0c;CNCF \u6280\u672f\u96f7\u8fbe\u63a8\u8350<\/li>\n<\/ul>\n<p>Axum \u7684\u6838\u5fc3\u8bbe\u8ba1\u54f2\u5b66\u53ea\u6709\u56db\u4e2a\u5b57&#xff1a;\u7c7b\u578b\u5373\u6587\u6863\u3002\u8def\u7531\u3001\u53c2\u6570\u63d0\u53d6\u3001\u4e2d\u95f4\u4ef6\u3001\u9519\u8bef\u5904\u7406\u2014\u2014\u5168\u90e8\u7528 Rust \u7c7b\u578b\u7cfb\u7edf\u6765\u8868\u8fbe&#xff0c;\u7f16\u8bd1\u5668\u5c31\u662f\u4f60\u7684\u7b2c\u4e00\u9053\u9632\u7ebf\u3002<\/p>\n<hr \/>\n<h3 id=\"\u4e8c\u4e3a\u4ec0\u4e48\u9009-axum\u56db\u5927\u6838\u5fc3\u4f18\u52bf\">\u4e8c\u3001\u4e3a\u4ec0\u4e48\u9009 Axum&#xff1f;\u56db\u5927\u6838\u5fc3\u4f18\u52bf<\/h3>\n<h4 id=\"21-\u96f6\u5b8f\u58f0\u660e\u5f0f\u8def\u7531\">2.1 \u96f6\u5b8f\u58f0\u660e\u5f0f\u8def\u7531<\/h4>\n<p>\u5927\u591a\u6570 Rust Web \u6846\u67b6\u7528\u5b8f&#xff08;macro&#xff09;\u6765\u5b9a\u4e49\u8def\u7531&#xff0c;\u6bd4\u5982 Actix-web \u7684\u00a0#[get(&#034;\/users\/{id}&#034;)]\u3002\u8fd9\u79cd\u5199\u6cd5\u7684\u786c\u4f24\u5728\u4e8e&#xff1a;\u5b8f\u5185\u90e8\u51fa\u9519\u65f6&#xff0c;\u7f16\u8bd1\u5668\u7684\u62a5\u9519\u4fe1\u606f\u8ba9\u4eba\u60f3\u6454\u952e\u76d8\u3002<\/p>\n<p>Axum \u76f4\u63a5\u629b\u5f03\u4e86\u8def\u7531\u5b8f\u3002\u8def\u7531\u7528\u7eaf Rust \u51fd\u6570\u94fe\u5f0f\u7ec4\u5408&#xff1a;<\/p>\n<p>let app &#061; Router::new()<br \/>\n    .route(&#034;\/users&#034;, get(list_users).post(create_user))<br \/>\n    .route(&#034;\/users\/{id}&#034;, get(get_user).delete(delete_user));<\/p>\n<p>\u6ca1\u6709\u4efb\u4f55\u9b54\u6cd5\u3002\u4f60\u770b\u5230\u7684\u5c31\u662f\u771f\u76f8\u3002IDE \u80fd\u76f4\u63a5\u8df3\u8f6c&#xff0c;\u7f16\u8bd1\u5668\u9519\u8bef\u6307\u54ea\u6253\u54ea\u2014\u2014\u8fd9\u5bf9\u56e2\u961f\u534f\u4f5c\u548c\u5927\u578b\u9879\u76ee\u7684\u7ef4\u62a4\u4f53\u9a8c\u662f\u8d28\u7684\u53d8\u5316\u3002<\/p>\n<h4 id=\"22-\u7c7b\u578b\u5b89\u5168\u7684\u63d0\u53d6\u5668extractor\u4f53\u7cfb\">2.2 \u7c7b\u578b\u5b89\u5168\u7684\u63d0\u53d6\u5668&#xff08;Extractor&#xff09;\u4f53\u7cfb<\/h4>\n<p>Axum \u7684&#034;\u63d0\u53d6\u5668&#034;\u662f\u5b83\u6700\u4eae\u773c\u7684\u8bbe\u8ba1\u3002\u4efb\u4f55\u4ece\u8bf7\u6c42\u4e2d\u63d0\u53d6\u6570\u636e\u7684\u884c\u4e3a\u2014\u2014\u8def\u5f84\u53c2\u6570\u3001\u67e5\u8be2\u5b57\u7b26\u4e32\u3001\u8bf7\u6c42\u4f53 JSON\u3001Header\u2014\u2014\u90fd\u901a\u8fc7\u5b9e\u73b0\u00a0FromRequest\u00a0trait \u6765\u5b8c\u6210\u3002<\/p>\n<p>\/\/ \u8def\u5f84\u53c2\u6570&#xff1a;\/users\/{id} \u2192 id: i32<br \/>\nasync fn get_user(Path(id): Path&lt;i32&gt;) -&gt; impl IntoResponse { &#8230; }<\/p>\n<p>\/\/ JSON \u8bf7\u6c42\u4f53&#xff1a;\u81ea\u52a8\u53cd\u5e8f\u5217\u5316 &#043; 400 \u9519\u8bef<br \/>\nasync fn create_user(Json(payload): Json&lt;CreateUserRequest&gt;) -&gt; impl IntoResponse { &#8230; }<\/p>\n<p>\/\/ \u67e5\u8be2\u5b57\u7b26\u4e32&#xff1a;\/search?keyword&#061;rust&amp;page&#061;2<br \/>\nasync fn search(Query(params): Query&lt;SearchParams&gt;) -&gt; impl IntoResponse { &#8230; }<\/p>\n<p>\/\/ \u7ec4\u5408\u63d0\u53d6&#xff1a;\u4e00\u884c\u4ee3\u7801\u62ff\u5230\u591a\u79cd\u6570\u636e<br \/>\nasync fn update(<br \/>\n    State(db): State&lt;DbPool&gt;,<br \/>\n    Path(id): Path&lt;i32&gt;,<br \/>\n    Json(payload): Json&lt;UpdateRequest&gt;,<br \/>\n) -&gt; Result&lt;Json&lt;User&gt;, AppError&gt; { &#8230; }<\/p>\n<p>\u5982\u679c\u4e00\u4e2a Extractor \u7ec4\u5408\u5728\u7c7b\u578b\u4e0a\u4e0d\u6210\u7acb&#xff0c;\u4ee3\u7801\u6839\u672c\u7f16\u8bd1\u4e0d\u8fc7\u3002\u4f60\u5728 Express \u91cc\u9700\u8981\u8dd1\u5230\u7ebf\u4e0a\u624d\u4f1a\u70b8\u7684\u53c2\u6570\u6821\u9a8c\u9519\u8bef&#xff0c;\u5728 Axum \u91cc&#xff0c;\u4fdd\u5b58\u6587\u4ef6\u90a3\u4e00\u77ac\u95f4\u5c31\u5df2\u7ecf\u88ab\u6d88\u706d\u4e86\u3002<\/p>\n<h4 id=\"23-tower-\u4e2d\u95f4\u4ef6\u751f\u6001\u5168\u9762\u63a5\u5165\">2.3 Tower \u4e2d\u95f4\u4ef6\u751f\u6001\u5168\u9762\u63a5\u5165<\/h4>\n<p>\u8fd9\u662f\u4e00\u4e2a\u88ab\u4e25\u91cd\u4f4e\u4f30\u7684\u6740\u624b\u7ea7\u4f18\u52bf\u3002<\/p>\n<p>Tower \u662f Rust \u5f02\u6b65\u751f\u6001\u7684\u4e2d\u95f4\u4ef6\u6807\u51c6&#xff0c;\u76f8\u5f53\u4e8e Java \u7684 Servlet Filter &#043; Netty \u7684 ChannelHandler \u7684\u5408\u4f53\u3002Axum \u5929\u751f\u517c\u5bb9\u6574\u4e2a Tower \u751f\u6001\u2014\u2014\u4f60\u4e0d\u9700\u8981\u7b49\u6846\u67b6\u4f5c\u8005\u652f\u6301\u67d0\u4e2a\u4e2d\u95f4\u4ef6&#xff0c;\u793e\u533a\u5df2\u7ecf\u6709\u6210\u767e\u4e0a\u5343\u4e2a\u73b0\u6210\u7684 Tower \u4e2d\u95f4\u4ef6\u53ef\u7528&#xff1a;<\/p>\n<table>\n<tbody>\n<tr>\n<td style=\"background-color:#dddddd\">\u4e2d\u95f4\u4ef6<\/td>\n<td style=\"background-color:#dddddd\">\u7528\u9014<\/td>\n<td style=\"background-color:#dddddd\">\u6240\u9700\u4f9d\u8d56<\/td>\n<\/tr>\n<tr>\n<td>tower-http::cors<\/td>\n<td>CORS \u8de8\u57df<\/td>\n<td>tower-http &#061; &#034;0.6&#034;<\/td>\n<\/tr>\n<tr>\n<td>tower-http::compression<\/td>\n<td>gzip\/brotli \u538b\u7f29<\/td>\n<td>tower-http &#061; &#034;0.6&#034;<\/td>\n<\/tr>\n<tr>\n<td>tower-http::trace<\/td>\n<td>\u8bf7\u6c42\u65e5\u5fd7\u8ffd\u8e2a<\/td>\n<td>tower-http &#061; &#034;0.6&#034;<\/td>\n<\/tr>\n<tr>\n<td>tower::limit::rate<\/td>\n<td>\u901f\u7387\u9650\u5236<\/td>\n<td>tower &#061; &#034;0.5&#034;<\/td>\n<\/tr>\n<tr>\n<td>tower::timeout<\/td>\n<td>\u8bf7\u6c42\u8d85\u65f6\u63a7\u5236<\/td>\n<td>tower &#061; &#034;0.5&#034;<\/td>\n<\/tr>\n<tr>\n<td>tower-http::auth<\/td>\n<td>\u8ba4\u8bc1\/\u9274\u6743<\/td>\n<td>tower-http &#061; &#034;0.6&#034;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4e00\u884c\u4ee3\u7801\u6302\u8f7d\u4e2d\u95f4\u4ef6&#xff1a;<\/p>\n<p>let app &#061; Router::new()<br \/>\n    .route(&#034;\/api&#034;, get(handler))<br \/>\n    .layer(TraceLayer::new_for_http())          \/\/ \u81ea\u52a8\u8bb0\u5f55\u6bcf\u4e2a\u8bf7\u6c42<br \/>\n    .layer(CompressionLayer::new())              \/\/ \u81ea\u52a8\u538b\u7f29\u54cd\u5e94\u4f53<br \/>\n    .layer(CorsLayer::permissive())              \/\/ \u5f00\u53d1\u73af\u5883\u653e\u5f00 CORS<br \/>\n    .layer(TimeoutLayer::new(Duration::from_secs(30))); \/\/ 30s \u8d85\u65f6<\/p>\n<h4 id=\"24-tokio-\u4eb2\u513f\u5b50\u6027\u80fd\u4e0e\u53ef\u9760\u6027\">2.4 Tokio \u4eb2\u513f\u5b50\u2014\u2014\u6027\u80fd\u4e0e\u53ef\u9760\u6027<\/h4>\n<p>Axum \u7531 Tokio \u6838\u5fc3\u56e2\u961f\u5f00\u53d1\u7ef4\u62a4\u3002\u8fd9\u610f\u5473\u7740\u4ec0\u4e48&#xff1f;<\/p>\n<ul>\n<li>\u96f6\u4e2d\u95f4\u5546\u8d5a\u5dee\u4ef7&#xff1a;\u76f4\u63a5\u8fd0\u884c\u5728 Tokio \u5f02\u6b65\u8fd0\u884c\u65f6\u4e0a&#xff0c;\u6ca1\u6709\u62bd\u8c61\u5c42\u635f\u8017<\/li>\n<li>\u4f18\u5148\u9002\u914d&#xff1a;Tokio \u7684\u65b0\u7279\u6027&#xff0c;Axum \u603b\u662f\u7b2c\u4e00\u4e2a\u652f\u6301<\/li>\n<li>\u957f\u671f\u7ef4\u62a4\u627f\u8bfa&#xff1a;Tokio \u662f Rust \u5f02\u6b65\u751f\u6001\u7684\u5730\u57fa&#xff0c;\u53ea\u8981 Tokio \u4e0d\u51c9&#xff0c;Axum \u5c31\u4e0d\u4f1a\u51c9<\/li>\n<\/ul>\n<p>\u5b9e\u6d4b\u6570\u636e&#xff08;TechEmpower 2026 \u57fa\u51c6\u6d4b\u8bd5&#xff09;&#xff1a;Axum \u5728**\u7eaf\u6846\u67b6&#xff08;\u65e0 ORM&#xff09;**\u573a\u666f\u4e0b&#xff0c;\u5355\u673a QPS \u8fbe\u5230 620 \u4e07&#xff0c;\u6bd4 Express.js \u5feb\u7ea6 18 \u500d&#xff0c;\u6bd4 Spring Boot \u5feb\u7ea6 7 \u500d\u3002<\/p>\n<hr \/>\n<h3 id=\"\u4e09\u9002\u7528\u573a\u666f\u4ec0\u4e48\u65f6\u5019\u8be5\u7528-axum\">\u4e09\u3001\u9002\u7528\u573a\u666f&#xff1a;\u4ec0\u4e48\u65f6\u5019\u8be5\u7528 Axum&#xff1f;<\/h3>\n<h4 id=\"31-\u5fae\u670d\u52a1-api-\u7f51\u5173-bff-\u5c42\u5f3a\u70c8\u63a8\u8350\">3.1 \u5fae\u670d\u52a1 API \u7f51\u5173 \/ BFF \u5c42&#xff08;\u5f3a\u70c8\u63a8\u8350&#xff09;<\/h4>\n<p>\u5fae\u670d\u52a1\u67b6\u6784\u4e2d\u5bf9\u6027\u80fd\u654f\u611f\u3001\u903b\u8f91\u8f83\u8f7b\u7684 API \u5c42&#xff0c;\u662f Axum \u7684\u6700\u4f73\u7528\u6b66\u4e4b\u5730\u3002<\/p>\n<p>\u7406\u7531&#xff1a;<\/p>\n<ul>\n<li>\u6781\u4f4e\u7684\u8d44\u6e90\u5360\u7528&#xff08;\u5185\u5b58 ~10MB \u8d77&#xff0c;\u5bf9\u6bd4 Spring Boot ~200MB&#xff09;<\/li>\n<li>\u51b7\u542f\u52a8\u901f\u5ea6\u6781\u5feb&#xff08;\u6beb\u79d2\u7ea7&#xff0c;\u9002\u5408 Serverless\/\u5bb9\u5668\u5f39\u6027\u4f38\u7f29&#xff09;<\/li>\n<li>\u7c7b\u578b\u5b89\u5168\u7684 API \u5b9a\u4e49&#xff0c;\u5929\u7136\u9002\u914d OpenAPI \/ gRPC-transcoding<\/li>\n<\/ul>\n<p>\u53cd\u4f8b&#xff1a;\u5982\u679c\u4f60\u7684\u670d\u52a1\u5c42\u91cd\u5ea6\u4f9d\u8d56 Spring \u751f\u6001\u7ec4\u4ef6&#xff08;\u5982 Spring Security OAuth2 \u5b8c\u6574\u5b9e\u73b0&#xff09;&#xff0c;\u90a3\u9009 Spring Boot \u66f4\u52a1\u5b9e\u3002<\/p>\n<h4 id=\"32-\u9ad8\u6027\u80fd\u5b9e\u65f6\u901a\u4fe1\u670d\u52a1\">3.2 \u9ad8\u6027\u80fd\u5b9e\u65f6\u901a\u4fe1\u670d\u52a1<\/h4>\n<p>\u914d\u5408 Tokio \u7684\u5f02\u6b65 I\/O&#xff0c;Axum \u5904\u7406 WebSocket \u957f\u8fde\u63a5\u7684\u80fd\u529b\u975e\u5e38\u4eae\u773c&#xff1a;<\/p>\n<p>async fn ws_handler(ws: WebSocketUpgrade) -&gt; impl IntoResponse {<br \/>\n    ws.on_upgrade(|socket| async move {<br \/>\n        let (mut sender, mut receiver) &#061; socket.split();<br \/>\n        \/\/ \u53cc\u5de5\u901a\u4fe1\u903b\u8f91<br \/>\n    })<br \/>\n}<\/p>\n<p>\u9002\u5408\u804a\u5929\u670d\u52a1\u3001\u6e38\u620f\u670d\u52a1\u5668\u3001\u5b9e\u65f6\u6570\u636e\u63a8\u9001\u7b49\u573a\u666f\u3002<\/p>\n<h4 id=\"33-\u8fb9\u7f18\u8ba1\u7b97-wasm-\u90e8\u7f72\">3.3 \u8fb9\u7f18\u8ba1\u7b97 \/ WASM \u90e8\u7f72<\/h4>\n<p>Axum \u7684\u4f53\u79ef\u5c0f\u5230\u53ef\u4ee5\u7f16\u8bd1\u4e3a WASM \u8fd0\u884c\u5728 Cloudflare Workers \/ Fastly Compute \u4e0a&#xff0c;\u8fd9\u662f JVM \u548c Node.js \u65e0\u6cd5\u4f01\u53ca\u7684\u3002<\/p>\n<h4 id=\"34-\u66ff\u4ee3\u8001\u65e7\u7684-expressfastify-\u670d\u52a1\u6e10\u8fdb\u5f0f\u8fc1\u79fb\">3.4 \u66ff\u4ee3\u8001\u65e7\u7684 Express\/Fastify \u670d\u52a1&#xff08;\u6e10\u8fdb\u5f0f\u8fc1\u79fb&#xff09;<\/h4>\n<p>\u5982\u679c\u4f60\u7684 Node.js \u670d\u52a1\u56e0\u4e3a\u5355\u7ebf\u7a0b\u74f6\u9888\u6491\u4e0d\u4f4f\u6d41\u91cf\u4e86&#xff0c;\u7528 Axum \u91cd\u5199\u6838\u5fc3\u70ed\u8def\u5f84\u662f\u6700\u4f4e\u6210\u672c\u7684\u4f18\u5316\u65b9\u6848\u3002Rust \u7684\u5185\u5b58\u5b89\u5168\u4fdd\u8bc1\u8ba9\u4f60\u4e0d\u4f1a\u56e0\u4e3a\u5fd8\u4e86\u00a0await\u00a0\u67d0\u4e2a Promise \u800c\u70b8\u7ebf\u4e0a\u3002<\/p>\n<hr \/>\n<h3 id=\"\u56db30-\u5206\u949f\u4e0a\u624b\u4ece\u96f6\u5230\u751f\u4ea7\u7ea7-api\">\u56db\u300130 \u5206\u949f\u4e0a\u624b&#xff1a;\u4ece\u96f6\u5230\u751f\u4ea7\u7ea7 API<\/h3>\n<p>\u4e0b\u9762\u5e26\u4f60\u4ece\u00a0cargo init\u00a0\u5f00\u59cb&#xff0c;\u642d\u5efa\u4e00\u4e2a\u5305\u542b\u6570\u636e\u5e93\u3001\u8ba4\u8bc1\u3001\u9519\u8bef\u5904\u7406\u7684\u5b8c\u6574 API \u670d\u52a1\u3002<\/p>\n<h4 id=\"41-\u9879\u76ee\u521d\u59cb\u5316\">4.1 \u9879\u76ee\u521d\u59cb\u5316<\/h4>\n<p># Cargo.toml<br \/>\n[package]<br \/>\nname &#061; &#034;my-api&#034;<br \/>\nversion &#061; &#034;0.1.0&#034;<br \/>\nedition &#061; &#034;2021&#034;<\/p>\n<p>[dependencies]<br \/>\naxum &#061; &#034;0.8&#034;<br \/>\ntokio &#061; { version &#061; &#034;1&#034;, features &#061; [&#034;full&#034;] }<br \/>\nserde &#061; { version &#061; &#034;1&#034;, features &#061; [&#034;derive&#034;] }<br \/>\nserde_json &#061; &#034;1&#034;<br \/>\nsqlx &#061; { version &#061; &#034;0.8&#034;, features &#061; [&#034;runtime-tokio&#034;, &#034;postgres&#034;] }<br \/>\ntower-http &#061; { version &#061; &#034;0.6&#034;, features &#061; [&#034;cors&#034;, &#034;trace&#034;, &#034;compression&#034;] }<br \/>\ntracing &#061; &#034;0.1&#034;<br \/>\ntracing-subscriber &#061; &#034;0.3&#034;<br \/>\nuuid &#061; { version &#061; &#034;1&#034;, features &#061; [&#034;v4&#034;] }<br \/>\nchrono &#061; { version &#061; &#034;0.4&#034;, features &#061; [&#034;serde&#034;] }<\/p>\n<h4 id=\"42-\u5b9a\u4e49\u6570\u636e\u6a21\u578b\">4.2 \u5b9a\u4e49\u6570\u636e\u6a21\u578b<\/h4>\n<p>\/\/ src\/models.rs<br \/>\nuse serde::{Deserialize, Serialize};<br \/>\nuse sqlx::FromRow;<br \/>\nuse uuid::Uuid;<br \/>\nuse chrono::{DateTime, Utc};<\/p>\n<p>#[derive(Debug, Serialize, Deserialize, FromRow)]<br \/>\npub struct User {<br \/>\n    pub id: Uuid,<br \/>\n    pub name: String,<br \/>\n    pub email: String,<br \/>\n    pub created_at: DateTime&lt;Utc&gt;,<br \/>\n}<\/p>\n<p>#[derive(Debug, Deserialize)]<br \/>\npub struct CreateUserRequest {<br \/>\n    pub name: String,<br \/>\n    pub email: String,<br \/>\n}<\/p>\n<p>#[derive(Debug, Deserialize)]<br \/>\npub struct ListUsersQuery {<br \/>\n    pub page: Option&lt;i64&gt;,<br \/>\n    pub per_page: Option&lt;i64&gt;,<br \/>\n}<\/p>\n<h4 id=\"43-\u6784\u5efa\u9519\u8bef\u5904\u7406\u4f53\u7cfb\">4.3 \u6784\u5efa\u9519\u8bef\u5904\u7406\u4f53\u7cfb<\/h4>\n<p>\/\/ src\/error.rs<br \/>\nuse axum::{<br \/>\n    http::StatusCode,<br \/>\n    response::{IntoResponse, Response},<br \/>\n    Json,<br \/>\n};<br \/>\nuse serde_json::json;<\/p>\n<p>#[derive(Debug)]<br \/>\npub enum AppError {<br \/>\n    NotFound(String),<br \/>\n    BadRequest(String),<br \/>\n    Internal(String),<br \/>\n}<\/p>\n<p>impl IntoResponse for AppError {<br \/>\n    fn into_response(self) -&gt; Response {<br \/>\n        let (status, message) &#061; match self {<br \/>\n            AppError::NotFound(msg) &#061;&gt; (StatusCode::NOT_FOUND, msg),<br \/>\n            AppError::BadRequest(msg) &#061;&gt; (StatusCode::BAD_REQUEST, msg),<br \/>\n            AppError::Internal(msg) &#061;&gt; (StatusCode::INTERNAL_SERVER_ERROR, msg),<br \/>\n        };<br \/>\n        (status, Json(json!({ &#034;error&#034;: message }))).into_response()<br \/>\n    }<br \/>\n}<\/p>\n<p>\/\/ \u5c06 sqlx::Error \u8f6c\u6362\u4e3a AppError<br \/>\nimpl From&lt;sqlx::Error&gt; for AppError {<br \/>\n    fn from(err: sqlx::Error) -&gt; Self {<br \/>\n        match err {<br \/>\n            sqlx::Error::RowNotFound &#061;&gt; AppError::NotFound(&#034;\u8d44\u6e90\u4e0d\u5b58\u5728&#034;.into()),<br \/>\n            _ &#061;&gt; AppError::Internal(format!(&#034;\u6570\u636e\u5e93\u9519\u8bef: {}&#034;, err)),<br \/>\n        }<br \/>\n    }<br \/>\n}<\/p>\n<h4 id=\"44-\u7f16\u5199-handler\">4.4 \u7f16\u5199 Handler<\/h4>\n<p>\/\/ src\/handlers.rs<br \/>\nuse axum::{<br \/>\n    extract::{Path, Query, State},<br \/>\n    Json,<br \/>\n};<br \/>\nuse uuid::Uuid;<br \/>\nuse sqlx::PgPool;<\/p>\n<p>use crate::error::AppError;<br \/>\nuse crate::models::{CreateUserRequest, ListUsersQuery, User};<\/p>\n<p>\/\/ \u521b\u5efa\u7528\u6237<br \/>\npub async fn create_user(<br \/>\n    State(db): State&lt;PgPool&gt;,<br \/>\n    Json(payload): Json&lt;CreateUserRequest&gt;,<br \/>\n) -&gt; Result&lt;(axum::http::StatusCode, Json&lt;User&gt;), AppError&gt; {<br \/>\n    let user &#061; sqlx::query_as::&lt;_, User&gt;(<br \/>\n        &#034;INSERT INTO users (name, email) VALUES ($1, $2) RETURNING *&#034;<br \/>\n    )<br \/>\n    .bind(&amp;payload.name)<br \/>\n    .bind(&amp;payload.email)<br \/>\n    .fetch_one(&amp;db)<br \/>\n    .await?;<\/p>\n<p>    Ok((axum::http::StatusCode::CREATED, Json(user)))<br \/>\n}<\/p>\n<p>\/\/ \u83b7\u53d6\u5355\u4e2a\u7528\u6237&#xff08;\u6309 UUID&#xff09;<br \/>\npub async fn get_user(<br \/>\n    State(db): State&lt;PgPool&gt;,<br \/>\n    Path(id): Path&lt;Uuid&gt;,<br \/>\n) -&gt; Result&lt;Json&lt;User&gt;, AppError&gt; {<br \/>\n    let user &#061; sqlx::query_as::&lt;_, User&gt;(&#034;SELECT * FROM users WHERE id &#061; $1&#034;)<br \/>\n        .bind(id)<br \/>\n        .fetch_one(&amp;db)<br \/>\n        .await?;<\/p>\n<p>    Ok(Json(user))<br \/>\n}<\/p>\n<p>\/\/ \u5206\u9875\u5217\u8868<br \/>\npub async fn list_users(<br \/>\n    State(db): State&lt;PgPool&gt;,<br \/>\n    Query(params): Query&lt;ListUsersQuery&gt;,<br \/>\n) -&gt; Result&lt;Json&lt;Vec&lt;User&gt;&gt;, AppError&gt; {<br \/>\n    let page &#061; params.page.unwrap_or(1).max(1);<br \/>\n    let per_page &#061; params.per_page.unwrap_or(20).min(100);<br \/>\n    let offset &#061; (page &#8211; 1) * per_page;<\/p>\n<p>    let users &#061; sqlx::query_as::&lt;_, User&gt;(<br \/>\n        &#034;SELECT * FROM users ORDER BY created_at DESC LIMIT $1 OFFSET $2&#034;<br \/>\n    )<br \/>\n    .bind(per_page)<br \/>\n    .bind(offset)<br \/>\n    .fetch_all(&amp;db)<br \/>\n    .await?;<\/p>\n<p>    Ok(Json(users))<br \/>\n}<\/p>\n<p>\/\/ \u5220\u9664\u7528\u6237<br \/>\npub async fn delete_user(<br \/>\n    State(db): State&lt;PgPool&gt;,<br \/>\n    Path(id): Path&lt;Uuid&gt;,<br \/>\n) -&gt; Result&lt;axum::http::StatusCode, AppError&gt; {<br \/>\n    let result &#061; sqlx::query(&#034;DELETE FROM users WHERE id &#061; $1&#034;)<br \/>\n        .bind(id)<br \/>\n        .execute(&amp;db)<br \/>\n        .await?;<\/p>\n<p>    if result.rows_affected() &#061;&#061; 0 {<br \/>\n        return Err(AppError::NotFound(&#034;\u7528\u6237\u4e0d\u5b58\u5728&#034;.into()));<br \/>\n    }<\/p>\n<p>    Ok(axum::http::StatusCode::NO_CONTENT)<br \/>\n}<\/p>\n<h4 id=\"45-\u7ec4\u88c5\u5e94\u7528\">4.5 \u7ec4\u88c5\u5e94\u7528<\/h4>\n<p>\/\/ src\/main.rs<br \/>\nmod error;<br \/>\nmod handlers;<br \/>\nmod models;<\/p>\n<p>use axum::{Router, routing::{delete, get, post}};<br \/>\nuse sqlx::PgPool;<br \/>\nuse tower_http::{<br \/>\n    cors::CorsLayer,<br \/>\n    compression::CompressionLayer,<br \/>\n    trace::TraceLayer,<br \/>\n};<br \/>\nuse tracing_subscriber;<\/p>\n<p>#[tokio::main]<br \/>\nasync fn main() {<br \/>\n    \/\/ \u521d\u59cb\u5316\u65e5\u5fd7<br \/>\n    tracing_subscriber::fmt::init();<\/p>\n<p>    \/\/ \u8fde\u63a5\u6570\u636e\u5e93&#xff08;\u5b9e\u9645\u9879\u76ee\u4e2d\u6539\u7528\u73af\u5883\u53d8\u91cf&#xff09;<br \/>\n    let db_url &#061; std::env::var(&#034;DATABASE_URL&#034;)<br \/>\n        .unwrap_or_else(|_| &#034;postgres:\/\/localhost\/myapp&#034;.to_string());<br \/>\n    let pool &#061; PgPool::connect(&amp;db_url).await<br \/>\n        .expect(&#034;\u6570\u636e\u5e93\u8fde\u63a5\u5931\u8d25&#034;);<\/p>\n<p>    \/\/ \u6267\u884c\u5efa\u8868&#xff08;\u751f\u4ea7\u73af\u5883\u8bf7\u7528 migration \u5de5\u5177&#xff09;<br \/>\n    sqlx::query(<br \/>\n        &#034;CREATE TABLE IF NOT EXISTS users (<br \/>\n            id UUID PRIMARY KEY DEFAULT gen_random_uuid(),<br \/>\n            name VARCHAR(100) NOT NULL,<br \/>\n            email VARCHAR(255) UNIQUE NOT NULL,<br \/>\n            created_at TIMESTAMPTZ DEFAULT NOW()<br \/>\n        )&#034;<br \/>\n    )<br \/>\n    .execute(&amp;pool)<br \/>\n    .await<br \/>\n    .expect(&#034;\u5efa\u8868\u5931\u8d25&#034;);<\/p>\n<p>    \/\/ \u6784\u5efa\u8def\u7531<br \/>\n    let app &#061; Router::new()<br \/>\n        .route(&#034;\/users&#034;, get(handlers::list_users).post(handlers::create_user))<br \/>\n        .route(&#034;\/users\/{id}&#034;, get(handlers::get_user).delete(handlers::delete_user))<br \/>\n        .layer(TraceLayer::new_for_http())       \/\/ \u8bf7\u6c42\u65e5\u5fd7<br \/>\n        .layer(CompressionLayer::new())          \/\/ \u54cd\u5e94\u538b\u7f29<br \/>\n        .layer(CorsLayer::permissive())          \/\/ CORS<br \/>\n        .with_state(pool);                       \/\/ \u6ce8\u5165\u6570\u636e\u5e93\u8fde\u63a5\u6c60<\/p>\n<p>    \/\/ \u542f\u52a8\u670d\u52a1<br \/>\n    let listener &#061; tokio::net::TcpListener::bind(&#034;0.0.0.0:3000&#034;).await.unwrap();<br \/>\n    tracing::info!(&#034;\u670d\u52a1\u542f\u52a8\u5728 http:\/\/0.0.0.0:3000&#034;);<br \/>\n    axum::serve(listener, app).await.unwrap();<br \/>\n}<\/p>\n<h4 id=\"46-\u6d4b\u8bd5\u4e00\u4e0b\">4.6 \u6d4b\u8bd5\u4e00\u4e0b<\/h4>\n<p># \u542f\u52a8<br \/>\nDATABASE_URL&#061;postgres:\/\/localhost\/myapp cargo run<\/p>\n<p># \u521b\u5efa\u7528\u6237<br \/>\ncurl -X POST http:\/\/localhost:3000\/users \\\\<br \/>\n  -H &#034;Content-Type: application\/json&#034; \\\\<br \/>\n  -d &#039;{&#034;name&#034;:&#034;\u5f20\u4e09&#034;,&#034;email&#034;:&#034;zhangsan&#064;example.com&#034;}&#039;<\/p>\n<p># \u54cd\u5e94&#xff1a;<br \/>\n# {&#034;id&#034;:&#034;3fa85f64-5717-4562-b3fc-2c963f66afa6&#034;,&#034;name&#034;:&#034;\u5f20\u4e09&#034;,&#034;email&#034;:&#034;zhangsan&#064;example.com&#034;,&#034;created_at&#034;:&#034;2026-07-24T08:30:00Z&#034;}<\/p>\n<p># \u83b7\u53d6\u7528\u6237<br \/>\ncurl http:\/\/localhost:3000\/users\/3fa85f64-5717-4562-b3fc-2c963f66afa6<\/p>\n<p># \u5206\u9875\u5217\u8868<br \/>\ncurl &#034;http:\/\/localhost:3000\/users?page&#061;1&amp;per_page&#061;10&#034;<\/p>\n<hr \/>\n<h3 id=\"\u4e94\u5bf9\u6bd4axum-vs-actix-web-vs-rocket2026-\u7248\">\u4e94\u3001\u5bf9\u6bd4&#xff1a;Axum vs Actix-web vs Rocket&#xff08;2026 \u7248&#xff09;<\/h3>\n<table>\n<tbody>\n<tr>\n<td style=\"background-color:#dddddd\">\u7ef4\u5ea6<\/td>\n<td style=\"background-color:#dddddd\">Axum 0.8<\/td>\n<td style=\"background-color:#dddddd\">Actix-web 4.x<\/td>\n<td style=\"background-color:#dddddd\">Rocket 0.5<\/td>\n<\/tr>\n<tr>\n<td>\u751f\u6001\u5b9a\u4f4d<\/td>\n<td>Tokio \u4eb2\u513f\u5b50<\/td>\n<td>\u72ec\u7acb\u8fd0\u884c\u65f6<\/td>\n<td>\u72ec\u7acb\u6846\u67b6<\/td>\n<\/tr>\n<tr>\n<td>\u8def\u7531\u65b9\u5f0f<\/td>\n<td>\u7eaf\u51fd\u6570\u94fe\u5f0f\u8c03\u7528<\/td>\n<td>\u5b8f\u00a0#[get(&#034;\/&#034;)]<\/td>\n<td>\u5b8f\u00a0#[get(&#034;\/&#034;)]<\/td>\n<\/tr>\n<tr>\n<td>\u4e2d\u95f4\u4ef6<\/td>\n<td>Tower \u5168\u751f\u6001<\/td>\n<td>\u81ea\u6709\u4f53\u7cfb<\/td>\n<td>\u81ea\u6709 Fairing<\/td>\n<\/tr>\n<tr>\n<td>\u5f02\u6b65\u8fd0\u884c\u65f6<\/td>\n<td>Tokio<\/td>\n<td>Actix RT<\/td>\n<td>Tokio<\/td>\n<\/tr>\n<tr>\n<td>Rust \u7248\u672c<\/td>\n<td>\u7a33\u5b9a\u7248\u5373\u53ef<\/td>\n<td>\u7a33\u5b9a\u7248\u5373\u53ef<\/td>\n<td>\u9700\u8981 nightly<\/td>\n<\/tr>\n<tr>\n<td>\u5b66\u4e60\u66f2\u7ebf<\/td>\n<td>\u5e73\u7f13&#xff08;\u7406\u89e3 Extractor \u5373\u53ef&#xff09;<\/td>\n<td>\u4e2d\u7b49<\/td>\n<td>\u5e73\u7f13\u4f46\u53d7 nightly \u9650\u5236<\/td>\n<\/tr>\n<tr>\n<td>\u751f\u4ea7\u6210\u719f\u5ea6<\/td>\n<td>Discord \/ AWS \/ Cloudflare<\/td>\n<td>\u5927\u91cf\u4f01\u4e1a\u7528\u6237<\/td>\n<td>\u504f\u793e\u533a\u9879\u76ee<\/td>\n<\/tr>\n<tr>\n<td>GitHub Stars<\/td>\n<td>20k&#043;<\/td>\n<td>31k&#043;<\/td>\n<td>24k&#043;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6211\u7684\u5efa\u8bae&#xff1a;<\/p>\n<ul>\n<li>\u65b0\u9879\u76ee\u00a0\u2192 Axum&#xff08;\u6ca1\u6709\u5386\u53f2\u5305\u88b1&#xff0c;\u9009\u672a\u6765&#xff09;<\/li>\n<li>\u9ad8\u6027\u80fd\u3001\u5df2\u6709 Actix \u7ecf\u9a8c\u4e14\u4e0d\u9700\u8981 Tower \u751f\u6001\u00a0\u2192 Actix-web&#xff08;\u4f9d\u7136\u662f\u6027\u80fd\u6807\u6746&#xff09;<\/li>\n<li>\u4e2a\u4eba\u9879\u76ee\u3001\u613f\u610f\u7528 nightly Rust\u00a0\u2192 Rocket&#xff08;\u5f00\u53d1\u4f53\u9a8c\u6700\u4e1d\u6ed1&#xff09;<\/li>\n<li>\u4e0d\u60f3\u6298\u817e&#xff0c;\u53ea\u60f3\u8d76\u7d27\u628a API \u8dd1\u8d77\u6765\u00a0\u2192 Axum<\/li>\n<\/ul>\n<hr \/>\n<h3 id=\"\u516d\u5e38\u89c1\u907f\u5751\u8981\u70b9\">\u516d\u3001\u5e38\u89c1\u907f\u5751\u8981\u70b9<\/h3>\n<h4 id=\"61-state-\u5fc5\u987b\u662f-clone-\u7684\">6.1 State \u5fc5\u987b\u662f Clone \u7684<\/h4>\n<p>axum::extract::State\u00a0\u8981\u6c42\u5176\u5185\u90e8\u7c7b\u578b\u5b9e\u73b0\u00a0Clone\u3002\u6570\u636e\u5e93\u8fde\u63a5\u6c60&#xff08;PgPool\u00a0\/\u00a0MySqlPool&#xff09;\u5929\u7136\u652f\u6301\u00a0Clone&#xff0c;\u56e0\u4e3a\u5b83\u5185\u90e8\u662f\u00a0Arc\u00a0\u5305\u88c5\u3002\u4f46\u5982\u679c\u4f20\u7684\u662f\u81ea\u5b9a\u4e49\u7ed3\u6784\u4f53&#xff0c;\u8bb0\u5f97\u6d3e\u751f\u00a0Clone\u3002<\/p>\n<h4 id=\"62-\u4e0d\u8981\u5728-handler-\u91cc\u505a\u91cd\u5ea6\u8ba1\u7b97\">6.2 \u4e0d\u8981\u5728 Handler \u91cc\u505a\u91cd\u5ea6\u8ba1\u7b97<\/h4>\n<p>Rust \u7684 async \u6a21\u578b\u662f\u534f\u4f5c\u5f0f\u8c03\u5ea6\u3002\u5982\u679c\u4f60\u7684 Handler \u91cc\u6709 CPU \u5bc6\u96c6\u578b\u64cd\u4f5c&#xff08;\u56fe\u7247\u5904\u7406\u3001\u5bc6\u7801\u54c8\u5e0c\u7b49&#xff09;&#xff0c;\u8bf7\u7528\u00a0tokio::task::spawn_blocking\u00a0\u628a\u5b83\u6254\u5230\u963b\u585e\u7ebf\u7a0b\u6c60\u3002<\/p>\n<p>async fn heavy_handler() -&gt; impl IntoResponse {<br \/>\n    let result &#061; tokio::task::spawn_blocking(|| {<br \/>\n        \/\/ \u91cd\u5ea6\u8ba1\u7b97\u903b\u8f91<br \/>\n        heavy_computation()<br \/>\n    })<br \/>\n    .await<br \/>\n    .unwrap();<\/p>\n<p>    Json(result)<br \/>\n}<\/p>\n<h4 id=\"63-\u9519\u8bef\u5904\u7406\u5c3d\u91cf\u7edf\u4e00\u9519\u8bef\u7c7b\u578b\">6.3 \u9519\u8bef\u5904\u7406&#xff1a;\u5c3d\u91cf\u7edf\u4e00\u9519\u8bef\u7c7b\u578b<\/h4>\n<p>\u4e0a\u9762\u7684\u793a\u4f8b\u5df2\u7ecf\u5c55\u793a\u4e86\u7528\u00a0AppError\u00a0\u679a\u4e3e\u7edf\u4e00\u9519\u8bef\u7c7b\u578b\u7684\u6a21\u5f0f\u3002\u4e0d\u8981\u5728 Handler \u91cc\u8fd4\u56de\u00a0Result&lt;Json&lt;T&gt;, Box&lt;dyn Error&gt;&gt;\u2014\u2014\u8fd9\u8ba9\u4e0b\u6e38\u5ba2\u6237\u7aef\u65e0\u6cd5\u533a\u5206 400 \u548c 500&#xff0c;\u8c03\u8bd5\u8d77\u6765\u975e\u5e38\u75db\u82e6\u3002<\/p>\n<h4 id=\"64-middleware-\u7684-layer-\u987a\u5e8f\u51b3\u5b9a\u903b\u8f91\">6.4 Middleware \u7684 layer \u987a\u5e8f\u51b3\u5b9a\u903b\u8f91<\/h4>\n<p>Router::new()<br \/>\n    .layer(TimeoutLayer::new(Duration::from_secs(10)))  \/\/ \u6700\u5148\u6267\u884c<br \/>\n    .layer(TraceLayer::new_for_http())                   \/\/ \u5176\u6b21<br \/>\n    .layer(CompressionLayer::new())                      \/\/ \u6700\u540e<\/p>\n<p>layer\u00a0\u7684\u5305\u88f9\u987a\u5e8f\u662f\u6d0b\u8471\u6a21\u578b&#xff1a;\u6700\u5916\u5c42 layer \u6700\u5148\u5904\u7406\u8bf7\u6c42\u3001\u6700\u540e\u5904\u7406\u54cd\u5e94\u3002\u8d85\u65f6\u5c42\u5fc5\u987b\u653e\u5728\u6700\u5916\u5c42&#xff0c;\u5426\u5219\u88ab\u538b\u7f29\u5c42\u6321\u4f4f&#xff0c;\u8d85\u65f6\u63a7\u5236\u53ef\u80fd\u5931\u6548\u3002<\/p>\n<hr \/>\n<h3 id=\"\u4e03\u603b\u7ed3\">\u4e03\u3001\u603b\u7ed3<\/h3>\n<p>Axum \u4e0d\u662f Rust Web \u6846\u67b6\u91cc\u529f\u80fd\u6700\u591a\u7684&#xff0c;\u4f46\u5b83\u662f\u6700&#034;Rust&#034;\u7684\u90a3\u4e2a\u2014\u2014\u5145\u5206\u5229\u7528\u7c7b\u578b\u7cfb\u7edf\u505a\u7f16\u8bd1\u671f\u68c0\u67e5&#xff0c;\u62d2\u7edd\u9b54\u6cd5\u5b8f&#xff0c;\u62e5\u62b1 Tower \u751f\u6001&#xff0c;\u9760 Tokio \u56e2\u961f\u80cc\u4e66\u957f\u671f\u7ef4\u62a4\u3002<\/p>\n<p>\u5982\u679c\u4f60\u6b63\u5728\u505a\u6280\u672f\u9009\u578b&#xff0c;\u6216\u8005\u60f3\u4ece Node.js \/ Spring Boot \u8fc1\u79fb\u4e00\u90e8\u5206\u670d\u52a1\u5230 Rust&#xff0c;Axum \u662f 2026 \u5e74\u6700\u7a33\u59a5\u7684\u9009\u62e9\u3002<\/p>\n<p>\u7528 Axum \u5199 API&#xff0c;\u4f60\u4e0d\u9700\u8981\u4fe1\u4efb\u6846\u67b6&#xff0c;\u4f60\u53ea\u9700\u8981\u4fe1\u4efb Rust \u7f16\u8bd1\u5668\u3002\u800c\u540e\u8005&#xff0c;\u662f\u6574\u4e2a\u7f16\u7a0b\u4e16\u754c\u91cc\u6700\u503c\u5f97\u4fe1\u4efb\u7684\u4e1c\u897f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u679c\u4f60\u8fd8\u5728\u7528 Express \u5199 API&#xff0c;\u6216\u8005\u88ab Actix-web \u7684\u5b8f\u5730\u72f1\u6298\u78e8\u8fc7&#xff0c;\u8fd9\u7bc7\u6587\u7ae0\u5c31\u662f\u4e3a\u4f60\u51c6\u5907\u7684\u3002 \u4e00\u3001Axum \u662f\u4ec0\u4e48&#xff1f;<br \/>\nAxum \u662f Tokio \u56e2\u961f\u5b98\u65b9\u7ef4\u62a4\u7684 Rust Web \u6846\u67b6&#xff0c;\u5b83\u7684\u5b9a\u4f4d\u975e\u5e38\u7cbe\u51c6&#xff1a;\u4e00\u4e2a\u57fa\u4e8e Tower \u4e2d\u95f4\u4ef6\u751f\u6001\u7684\u3001\u7c7b\u578b\u5b89\u5168\u7684\u3001\u6781\u7b80\u4e3b\u4e49 Web \u6846\u67b6\u3002<br \/>\n\u5b83\u4e0d\u662f\u4ec0\u4e48\\&#8221;\u745e\u58eb\u519b\u5200\\&#8221;&#xff0c;\u800c\u662f\u4e00\u628a\u6253\u78e8\u5230\u6781\u81f4\u7684\u65e5\u5f0f\u53a8\u5200\u2014\u2014\u53ea\u505a\u4e00\u4ef6\u4e8b&#xff0c;\u628a\u5b83\u505a\u5230\u6700\u597d&amp;#<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[9109,206,87,190],"topic":[],"class_list":["post-84914","post","type-post","status-publish","format-standard","hentry","category-server","tag-9109","tag-rust","tag-87","tag-190"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Axum\uff1a\u7528 Rust \u5199 Web \u540e\u7aef\u7684\u6b63\u786e\u6253\u5f00\u65b9\u5f0f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/84914.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Axum\uff1a\u7528 Rust \u5199 Web \u540e\u7aef\u7684\u6b63\u786e\u6253\u5f00\u65b9\u5f0f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u5982\u679c\u4f60\u8fd8\u5728\u7528 Express \u5199 API&#xff0c;\u6216\u8005\u88ab Actix-web \u7684\u5b8f\u5730\u72f1\u6298\u78e8\u8fc7&#xff0c;\u8fd9\u7bc7\u6587\u7ae0\u5c31\u662f\u4e3a\u4f60\u51c6\u5907\u7684\u3002 \u4e00\u3001Axum \u662f\u4ec0\u4e48&#xff1f; Axum \u662f Tokio \u56e2\u961f\u5b98\u65b9\u7ef4\u62a4\u7684 Rust Web \u6846\u67b6&#xff0c;\u5b83\u7684\u5b9a\u4f4d\u975e\u5e38\u7cbe\u51c6&#xff1a;\u4e00\u4e2a\u57fa\u4e8e Tower \u4e2d\u95f4\u4ef6\u751f\u6001\u7684\u3001\u7c7b\u578b\u5b89\u5168\u7684\u3001\u6781\u7b80\u4e3b\u4e49 Web \u6846\u67b6\u3002 \u5b83\u4e0d\u662f\u4ec0\u4e48&quot;\u745e\u58eb\u519b\u5200&quot;&#xff0c;\u800c\u662f\u4e00\u628a\u6253\u78e8\u5230\u6781\u81f4\u7684\u65e5\u5f0f\u53a8\u5200\u2014\u2014\u53ea\u505a\u4e00\u4ef6\u4e8b&#xff0c;\u628a\u5b83\u505a\u5230\u6700\u597d&amp;#\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/84914.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-07-26T12:41:52+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/84914.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/84914.html\",\"name\":\"Axum\uff1a\u7528 Rust \u5199 Web \u540e\u7aef\u7684\u6b63\u786e\u6253\u5f00\u65b9\u5f0f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-07-26T12:41:52+00:00\",\"dateModified\":\"2026-07-26T12:41:52+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/84914.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/84914.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/84914.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Axum\uff1a\u7528 Rust \u5199 Web \u540e\u7aef\u7684\u6b63\u786e\u6253\u5f00\u65b9\u5f0f\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Axum\uff1a\u7528 Rust \u5199 Web \u540e\u7aef\u7684\u6b63\u786e\u6253\u5f00\u65b9\u5f0f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/84914.html","og_locale":"zh_CN","og_type":"article","og_title":"Axum\uff1a\u7528 Rust \u5199 Web \u540e\u7aef\u7684\u6b63\u786e\u6253\u5f00\u65b9\u5f0f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u5982\u679c\u4f60\u8fd8\u5728\u7528 Express \u5199 API&#xff0c;\u6216\u8005\u88ab Actix-web \u7684\u5b8f\u5730\u72f1\u6298\u78e8\u8fc7&#xff0c;\u8fd9\u7bc7\u6587\u7ae0\u5c31\u662f\u4e3a\u4f60\u51c6\u5907\u7684\u3002 \u4e00\u3001Axum \u662f\u4ec0\u4e48&#xff1f; Axum \u662f Tokio \u56e2\u961f\u5b98\u65b9\u7ef4\u62a4\u7684 Rust Web \u6846\u67b6&#xff0c;\u5b83\u7684\u5b9a\u4f4d\u975e\u5e38\u7cbe\u51c6&#xff1a;\u4e00\u4e2a\u57fa\u4e8e Tower \u4e2d\u95f4\u4ef6\u751f\u6001\u7684\u3001\u7c7b\u578b\u5b89\u5168\u7684\u3001\u6781\u7b80\u4e3b\u4e49 Web \u6846\u67b6\u3002 \u5b83\u4e0d\u662f\u4ec0\u4e48\"\u745e\u58eb\u519b\u5200\"&#xff0c;\u800c\u662f\u4e00\u628a\u6253\u78e8\u5230\u6781\u81f4\u7684\u65e5\u5f0f\u53a8\u5200\u2014\u2014\u53ea\u505a\u4e00\u4ef6\u4e8b&#xff0c;\u628a\u5b83\u505a\u5230\u6700\u597d&amp;#","og_url":"https:\/\/www.wsisp.com\/helps\/84914.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-07-26T12:41:52+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"7 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/84914.html","url":"https:\/\/www.wsisp.com\/helps\/84914.html","name":"Axum\uff1a\u7528 Rust \u5199 Web \u540e\u7aef\u7684\u6b63\u786e\u6253\u5f00\u65b9\u5f0f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-07-26T12:41:52+00:00","dateModified":"2026-07-26T12:41:52+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/84914.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/84914.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/84914.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Axum\uff1a\u7528 Rust \u5199 Web \u540e\u7aef\u7684\u6b63\u786e\u6253\u5f00\u65b9\u5f0f"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/84914","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=84914"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/84914\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=84914"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=84914"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=84914"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=84914"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}