{"id":61230,"date":"2026-01-17T08:34:50","date_gmt":"2026-01-17T00:34:50","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/61230.html"},"modified":"2026-01-17T08:34:50","modified_gmt":"2026-01-17T00:34:50","slug":"%e5%9f%ba%e4%ba%8efastapi%e7%9a%84api%e5%bc%80%e5%8f%91%ef%bc%88%e7%88%ac%e8%99%ab%e7%9a%84%e5%b7%a5%e4%bd%9c%e5%8e%9f%e7%90%86%ef%bc%8c%e6%9c%8d%e5%8a%a1%e5%99%a8%e6%8e%a5%e5%8f%a3%e6%90%ad%e5%bb%ba","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/61230.html","title":{"rendered":"\u57fa\u4e8eFastAPI\u7684API\u5f00\u53d1\uff08\u722c\u866b\u7684\u5de5\u4f5c\u539f\u7406\uff0c\u670d\u52a1\u5668\u63a5\u53e3\u642d\u5efa\uff09\uff1a\u4ece\u8bbe\u8ba1\u5230\u90e8\u7f72\u8be6\u89e3+\u9762\u8bd5\u4e60\u9898"},"content":{"rendered":"<p>API&#xff08;Application Programming Interface&#xff09;\u662f\u4e0d\u540c\u8f6f\u4ef6\u7cfb\u7edf\u4e4b\u95f4\u7684\u901a\u4fe1\u63a5\u53e3&#xff0c;\u662f\u73b0\u4ee3\u8f6f\u4ef6\u67b6\u6784\u7684\u6838\u5fc3\u7ec4\u4ef6\u3002\u672c\u6587\u5c06\u4ece \u57fa\u7840\u6982\u5ff5\u5230\u5b9e\u9645\u5b9e\u73b0 &#xff0c;\u8be6\u7ec6\u8bb2\u89e3API\u5f00\u53d1\u7684\u5168\u6d41\u7a0b\u3002<\/p>\n<h2>\u4e00\u3001API\u57fa\u7840\u6982\u5ff5<\/h2>\n<h3> 1. \u4ec0\u4e48\u662fAPI&#xff1f;<\/h3>\n<p> API\u662f\u4e00\u7ec4\u5b9a\u4e49\u7684\u89c4\u5219\u548c\u534f\u8bae&#xff0c;\u5141\u8bb8\u4e00\u4e2a\u8f6f\u4ef6\u7cfb\u7edf\u4e0e\u53e6\u4e00\u4e2a\u8f6f\u4ef6\u7cfb\u7edf\u4ea4\u4e92&#xff0c;\u800c\u65e0\u9700\u4e86\u89e3\u5176\u5185\u90e8\u5b9e\u73b0\u7ec6\u8282\u3002<\/p>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p>&#8211; \u5929\u6c14\u5e94\u7528\u901a\u8fc7\u5929\u6c14API\u83b7\u53d6\u5b9e\u65f6\u5929\u6c14\u6570\u636e &#8211; \u79fb\u52a8\u5e94\u7528\u901a\u8fc7\u540e\u7aefAPI\u4e0e\u670d\u52a1\u5668\u901a\u4fe1<\/p>\n<h3> 2. API\u7684\u7c7b\u578b<\/h3>\n<p>&#8211; REST API &#xff1a;\u57fa\u4e8eHTTP\u534f\u8bae&#xff0c;\u4f7f\u7528\u6807\u51c6HTTP\u65b9\u6cd5&#xff0c;\u662f\u76ee\u524d\u6700\u6d41\u884c\u7684API\u7c7b\u578b &#8211; GraphQL API &#xff1a;\u5141\u8bb8\u5ba2\u6237\u7aef\u7cbe\u786e\u8bf7\u6c42\u6240\u9700\u6570\u636e&#xff0c;\u51cf\u5c11\u7f51\u7edc\u4f20\u8f93 &#8211; SOAP API &#xff1a;\u57fa\u4e8eXML\u7684\u91cd\u91cf\u7ea7API&#xff0c;\u4e3b\u8981\u7528\u4e8e\u4f01\u4e1a\u7ea7\u5e94\u7528 &#8211; WebSocket API &#xff1a;\u63d0\u4f9b\u53cc\u5411\u5b9e\u65f6\u901a\u4fe1&#xff0c;\u9002\u5408\u804a\u5929\u3001\u5b9e\u65f6\u66f4\u65b0\u7b49\u573a\u666f<\/p>\n<p><span style=\"background-color:#a2e043\">\u4f5c\u8005\u6709\u8bdd\u8bf4&#xff1a;<\/span><span style=\"background-color:null\">API\u5f00\u53d1\u4e00<\/span>\u822c\u90fd\u662fWebAPI\u5f00\u53d1\u3002<\/p>\n<h3> 3. API\u6838\u5fc3\u539f\u5219<\/h3>\n<p> REST&#xff08;Representational State Transfer&#xff09;\u662f\u4e00\u79cdAPI\u8bbe\u8ba1\u98ce\u683c&#xff0c;\u9075\u5faa\u4ee5\u4e0b\u539f\u5219&#xff1a;<\/p>\n<p>&#8211; \u8d44\u6e90\u4e3a\u4e2d\u5fc3 &#xff1a;\u4f7f\u7528URL\u8868\u793a\u8d44\u6e90&#xff08;\u5982 \/users \u3001 \/products\/123 &#xff09;<\/p>\n<p>&#8211; HTTP\u65b9\u6cd5\u8868\u793a\u64cd\u4f5c &#xff1a; \u00a0 &#8211; GET &#xff1a;\u83b7\u53d6\u8d44\u6e90 \u00a0 &#8211; POST &#xff1a;\u521b\u5efa\u8d44\u6e90 \u00a0 &#8211; PUT &#xff1a;\u66f4\u65b0\u8d44\u6e90 \u00a0 &#8211; PATCH &#xff1a;\u90e8\u5206\u66f4\u65b0\u8d44\u6e90 \u00a0 &#8211; DELETE &#xff1a;\u5220\u9664\u8d44\u6e90<\/p>\n<p>&#8211; \u65e0\u72b6\u6001 &#xff1a;\u6bcf\u4e2a\u8bf7\u6c42\u90fd\u5305\u542b\u5b8c\u6574\u7684\u72b6\u6001\u4fe1\u606f&#xff0c;\u670d\u52a1\u5668\u4e0d\u4fdd\u5b58\u5ba2\u6237\u7aef\u72b6\u6001 &#8211; \u7edf\u4e00\u63a5\u53e3 &#xff1a;\u4f7f\u7528\u6807\u51c6HTTP\u72b6\u6001\u7801\u548c\u5934\u4fe1\u606f &#8211; \u8d44\u6e90\u8868\u793a &#xff1a;\u4f7f\u7528JSON\u6216XML\u8868\u793a\u8d44\u6e90<\/p>\n<h2>\u4e8c\u3001HTTP\u8bf7\u6c42\u683c\u5f0f<\/h2>\n<\/p>\n<p>GET\u8bf7\u6c42&#xff1a;\u00a0\u67e5\u8be2\u8bf7\u6c42&#xff08;get\u8bf7\u6c42&#xff09;\u4e00\u822c\u8bf7\u6c42\u4f53\u4e3a\u7a7a<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"408\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260117003444-696ad924bd917.png\" width=\"759\" \/><\/p>\n<h2>\u56db\u3001HTTP\u54cd\u5e94\u683c\u5f0f<\/h2>\n<\/p>\n<p>post\u8bf7\u6c42&#xff1a;\u63d0\u4ea4\u4fee\u6539\u8bf7\u6c42&#xff08;\u9690\u79d8\u6570\u636e\u4fee\u6539post\u8bf7\u6c42&#xff09;\u4e00\u822c\u52a0\u5bc6&#xff1b;\u8bf7\u6c42\u4f53\u4e00\u822c\u4e0d\u663e\u793a\u5728URL\u4e2d<\/p>\n<p>\\\\r\\\\n\\\\r\\\\n:\u6362\u884c\u8bf7\u6c42\u4f53\u548c\u8bf7\u6c42\u884c\u4e2d\u95f4\u4e00\u4e2a\u7a7a\u884c<\/p>\n<p>\u54cd\u5e94\u534f\u8bae\u683c\u5f0f<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"515\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260117003444-696ad924da962.png\" width=\"485\" \/><\/p>\n<p>\u56de\u6765\u6d41\u7a0b&#xff1a;<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"433\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260117003445-696ad92501cac.png\" width=\"815\" \/><\/p>\n<h2> \u4e94\u3001API\u8bbe\u8ba1&#xff1a;\u89c4\u8303\u4e0e\u6700\u4f73\u5b9e\u8df5<\/h2>\n<h3> 1. \u8bbe\u8ba1\u6d41\u7a0b<\/h3>\n<p>1. \u9700\u6c42\u5206\u6790 &#xff1a;\u660e\u786eAPI\u7684\u529f\u80fd\u548c\u4f7f\u7528\u573a\u666f 2. \u8d44\u6e90\u5efa\u6a21 &#xff1a;\u8bc6\u522b\u7cfb\u7edf\u4e2d\u7684\u6838\u5fc3\u8d44\u6e90&#xff08;\u5982\u7528\u6237\u3001\u4ea7\u54c1\u3001\u8ba2\u5355&#xff09; 3. \u8def\u5f84\u8bbe\u8ba1 &#xff1a;\u4e3a\u6bcf\u4e2a\u8d44\u6e90\u5b9a\u4e49\u6e05\u6670\u7684URL\u8def\u5f84 4. \u53c2\u6570\u8bbe\u8ba1 &#xff1a;\u5b9a\u4e49\u67e5\u8be2\u53c2\u6570\u3001\u8def\u5f84\u53c2\u6570\u548c\u8bf7\u6c42\u4f53 5. \u54cd\u5e94\u8bbe\u8ba1 &#xff1a;\u5b9a\u4e49\u54cd\u5e94\u683c\u5f0f\u548c\u72b6\u6001\u7801 6. \u8ba4\u8bc1\u6388\u6743 &#xff1a;\u8bbe\u8ba1\u5b89\u5168\u673a\u5236<\/p>\n<h3> 2. URL\u8def\u5f84\u8bbe\u8ba1<\/h3>\n<p>&#8211; \u4f7f\u7528\u590d\u6570\u540d\u8bcd &#xff1a; \/users \u800c\u975e \/user &#8211; \u5d4c\u5957\u8d44\u6e90 &#xff1a;\u8868\u793a\u8d44\u6e90\u4e4b\u95f4\u7684\u5173\u7cfb&#xff0c;\u5982 \/users\/123\/orders &#8211; \u907f\u514d\u52a8\u8bcd &#xff1a;\u4f7f\u7528HTTP\u65b9\u6cd5\u8868\u793a\u64cd\u4f5c&#xff0c;\u800c\u975eURL\u4e2d\u5305\u542b\u52a8\u8bcd&#xff08;\u5982 \/users\/123 \u800c\u975e \/getUser\/123 &#xff09; &#8211; \u4fdd\u6301\u7b80\u6d01 &#xff1a;\u907f\u514d\u8fc7\u957f\u6216\u590d\u6742\u7684\u8def\u5f84<\/p>\n<p>URL&#xff1a;\u672c\u8d28\u4e0a\u662f\u5411\u670d\u52a1\u5668\u589e\u5220\u6539\u67e5\u6570\u636e&#xff0c;\u591a\u6570\u662f\u67e5<\/p>\n<p>\u534f\u8bae&#xff1a;\/\/\u57df\u540d\/\u8def\u5f84&#xff1f;\u67e5\u5bfb\u53c2\u6570<\/p>\n<h3> 3. \u8bf7\u6c42\u4e0e\u54cd\u5e94\u8bbe\u8ba1 \u8bf7\u6c42\u8bbe\u8ba1<\/h3>\n<\/p>\n<p>&#8211; \u8def\u5f84\u53c2\u6570 &#xff1a;\u7528\u4e8e\u6807\u8bc6\u7279\u5b9a\u8d44\u6e90&#xff08;\u5982 \/users\/{id} &#xff09; &#8211; \u67e5\u8be2\u53c2\u6570 &#xff1a;\u7528\u4e8e\u8fc7\u6ee4\u3001\u6392\u5e8f\u548c\u5206\u9875&#xff08;\u5982 \/users?page&#061;1&amp;limit&#061;10 &#xff09; &#8211; \u8bf7\u6c42\u4f53 &#xff1a;\u7528\u4e8e\u521b\u5efa\u6216\u66f4\u65b0\u8d44\u6e90&#xff0c;\u901a\u5e38\u4f7f\u7528JSON\u683c\u5f0f &#8211; \u5934\u4fe1\u606f &#xff1a;\u7528\u4e8e\u4f20\u9012\u5143\u6570\u636e&#xff08;\u5982\u8ba4\u8bc1\u4ee4\u724c\u3001\u5185\u5bb9\u7c7b\u578b&#xff09; \u54cd\u5e94\u8bbe\u8ba1<\/p>\n<p>&#8211; \u4f7f\u7528\u6807\u51c6HTTP\u72b6\u6001\u7801 &#xff1a;<\/p>\n<p>\u00a0 &#8211; 200 OK&#xff1a;\u8bf7\u6c42\u6210\u529f \u00a0 &#8211; 201 Created&#xff1a;\u8d44\u6e90\u521b\u5efa\u6210\u529f \u00a0 &#8211; 204 No Content&#xff1a;\u8bf7\u6c42\u6210\u529f\u4f46\u65e0\u54cd\u5e94\u4f53 \u00a0 &#8211; 400 Bad Request&#xff1a;\u8bf7\u6c42\u683c\u5f0f\u9519\u8bef \u00a0 &#8211; 401 Unauthorized&#xff1a;\u672a\u6388\u6743 \u00a0 &#8211; 403 Forbidden&#xff1a;\u7981\u6b62\u8bbf\u95ee \u00a0 &#8211; 404 Not Found&#xff1a;\u8d44\u6e90\u672a\u627e\u5230 \u00a0 &#8211; 500 Internal Server Error&#xff1a;\u670d\u52a1\u5668\u5185\u90e8\u9519\u8bef<\/p>\n<p>&#8211; \u7edf\u4e00\u54cd\u5e94\u683c\u5f0f&#xff08;\u5b57\u5178\u5185\u5957\u5b57\u5178&#xff09; &#xff1a;<\/p>\n<p>{ \u00a0 &#034;status&#034;: &#034;success&#034;, \u00a0 &#034;data&#034;: {&#8230;}, \u00a0\/\/ \u54cd\u5e94\u6570\u636e \u00a0 &#034;message&#034;: &#034;\u8bf7\u6c42\u6210\u529f&#034; }<\/p>\n<p>\u9519\u8bef\u54cd\u5e94 &#xff08;\u5b57\u5178\u5185\u5957\u5b57\u5178\u53c8\u5957\u5217\u8868&#xff09;&#xff1a;<\/p>\n<p>{ \u00a0 &#034;status&#034;: &#034;error&#034;, \u00a0 &#034;error&#034;: { \u00a0 \u00a0 &#034;code&#034;: &#034;INVALID_PARAMETER&#034;, \u00a0 \u00a0 &#034;message&#034;: &#034;\u53c2\u6570\u9a8c\u8bc1\u5931\u8d25&#034;, \u00a0 \u00a0 &#034;details&#034;: [ \u00a0 \u00a0 \u00a0 {&#034;field&#034;: &#034;email&#034;, &#034;message&#034;: &#034;\u5fc5\u987b\u662f\u6709\u6548\u7684\u90ae\u7bb1\u5730\u5740&#034;} \u00a0 \u00a0 ] \u00a0 } }<\/p>\n<p>\u8fd4\u56de\u4e24\u79cd\u683c\u5f0f&#xff1a;josn\u548cHTML<\/p>\n<p>josn&#xff1a;\u63d0\u4f9b\u63a5\u53e3<\/p>\n<p>HTML&#xff1a;\u63d0\u4f9b\u7ed9\u7528\u6237<\/p>\n<h3>4. \u6570\u636e\u9a8c\u8bc1<\/h3>\n<p>&#8211; \u8bf7\u6c42\u53c2\u6570\u9a8c\u8bc1 &#xff1a;\u786e\u4fdd\u4f20\u5165\u7684\u6570\u636e\u7b26\u5408\u9884\u671f\u683c\u5f0f\u548c\u7ea6\u675f &#8211; \u6570\u636e\u7c7b\u578b\u9a8c\u8bc1 &#xff1a;\u68c0\u67e5\u5b57\u7b26\u4e32\u3001\u6570\u5b57\u3001\u65e5\u671f\u7b49\u7c7b\u578b &#8211; \u4e1a\u52a1\u89c4\u5219\u9a8c\u8bc1 &#xff1a;\u68c0\u67e5\u6570\u636e\u662f\u5426\u6ee1\u8db3\u4e1a\u52a1\u903b\u8f91\u8981\u6c42&#xff08;\u5982\u90ae\u7bb1\u552f\u4e00\u6027&#xff09;<\/p>\n<h2> \u516d\u3001API\u5f00\u53d1\u5b9e\u73b0<\/h2>\n<h3>1.\u4ec0\u4e48\u662f\u6846\u67b6&#xff1f;<\/h3>\n<p>\u5c31\u76f8\u5f53\u4e8e\u4e00\u4e2a\u6a21\u7248&#xff0c;\u6211\u5728\u8fd9\u4e2a\u6a21\u7248\u4e0a\u505a\u4e00\u4e9b\u4fee\u6539\u3002<\/p>\n<h3>2.\u4e0b\u8f7d\u6846\u67b6<\/h3>\n<p>pip install fastapi uvicorn <\/p>\n<h3>3.\u4ee3\u7801\u64b0\u5199&#xff08;\u7528AI\u7ed9\u4f60\u4e00\u4e2a\u6848\u4f8b&#xff0c;\u73b0\u5728\u6309\u7167\u6211\u751f\u6210\u8fd9\u4e2a\u6765\u6f14\u793a&#xff09;<\/h3>\n<p>from fastapi import FastAPI<br \/>\nfrom pydantic import BaseModel<br \/>\nfrom typing import List<\/p>\n<p># \u521b\u5efaFastAPI\u5e94\u7528\u5b9e\u4f8b\u5bf9\u8c61<br \/>\napp &#061; FastAPI(<br \/>\n    title&#061;&#034;\u7b80\u5355FastAPI\u793a\u4f8b&#034;,<br \/>\n    description&#061;&#034;\u8fd9\u662f\u4e00\u4e2a\u57fa\u7840\u7684FastAPI\u5e94\u7528\u793a\u4f8b&#034;,<br \/>\n    version&#061;&#034;1.0.0&#034;<br \/>\n)<\/p>\n<p># \u5b9a\u4e49\u6570\u636e\u6a21\u578b<br \/>\n# \u7528\u6237\u6a21\u578b,(\u76f8\u5f53\u4e8e\u5f3a\u5236\u6570\u636e\u7c7b\u578b)<br \/>\nclass User(BaseModel):<br \/>\n    name: str<br \/>\n    id: int<br \/>\n    email: str<\/p>\n<p># \u793a\u4f8b&#xff1a;\u521b\u5efa\u4e00\u4e2a users \u5217\u8868&#xff0c;\u5b58\u653e User \u6a21\u578b\u5b9e\u4f8b<br \/>\n#\u6a21\u62df\u6570\u636e\u5e93<br \/>\nusers_list &#061; [<br \/>\n    User(name&#061;&#034;\u5f20\u4e09&#034;, id&#061;1, email&#061;&#034;zhangsan&#064;example.com&#034;),<br \/>\n    User(name&#061;&#034;\u674e\u56db&#034;, id&#061;2, email&#061;&#034;lisi&#064;example.com&#034;),<br \/>\n    User(name&#061;&#034;\u738b\u4e94&#034;, id&#061;3, email&#061;&#034;wangwu&#064;example.com&#034;),<br \/>\n]<\/p>\n<p># \u5b9a\u4e49GET\u8bf7\u6c42<br \/>\n# \u83b7\u53d6\u6240\u6709\u7528\u6237<br \/>\n# \u54cd\u5e94\u6a21\u578b\u4e3a List[User]&#xff0c;\u8868\u793a\u8fd4\u56de\u4e00\u4e2a\u7528\u6237\u5217\u8868   \u8fd4\u56de\u7684\u6570\u636e\u683c\u5f0f\u5fc5\u987b\u4e3a User \u6a21\u578b\u7684\u683c\u5f0f<br \/>\n# \u8def\u5f84\u4e3a \/users&#xff0c;HTTP \u65b9\u6cd5\u4e3a GET<br \/>\n# \u51fd\u6570 get_users \u8fd4\u56de users_list \u5217\u8868<br \/>\n&#064;app.get(path&#061;&#034;\/users&#034;,response_model&#061;List[User])<br \/>\ndef get_users():<br \/>\n    return users_list<\/p>\n<p># \u5b9a\u4e49POST\u8bf7\u6c42<br \/>\n# \u521b\u5efa\u7528\u6237<br \/>\n# \u8bf7\u6c42\u6a21\u578b\u4e3a User&#xff0c;\u54cd\u5e94\u6a21\u578b\u4e5f\u4e3a User   (\u63d0\u4ea4\u7684\u6570\u636e\u683c\u5f0f\u5fc5\u987b\u4e3a User \u6a21\u578b\u7684\u683c\u5f0f)<br \/>\n# \u8def\u5f84\u4e3a \/users&#xff0c;HTTP \u65b9\u6cd5\u4e3a POST<br \/>\n# \u51fd\u6570 create_users \u63a5\u6536\u4e00\u4e2a User \u5b9e\u4f8b\u4f5c\u4e3a\u53c2\u6570&#xff0c;\u5c06\u5176\u6dfb\u52a0\u5230 users_list \u5217\u8868\u4e2d&#xff0c;\u5e76\u8fd4\u56de\u8be5\u5b9e\u4f8b<br \/>\n&#064;app.post(path&#061;&#034;\/users&#034;,response_model&#061;User)<br \/>\ndef create_users(user:User):<br \/>\n    users_list.append(user)<br \/>\n    return user<\/p>\n<p># \u5b9a\u4e49PUT\u8bf7\u6c42<br \/>\n# \u66f4\u65b0\u7528\u6237<br \/>\n# \u8bf7\u6c42\u6a21\u578b\u4e3a User&#xff0c;\u54cd\u5e94\u6a21\u578b\u4e5f\u4e3a User   (\u63d0\u4ea4\u7684\u6570\u636e\u683c\u5f0f\u5fc5\u987b\u4e3a User \u6a21\u578b\u7684\u683c\u5f0f)<br \/>\n# \u8def\u5f84\u4e3a \/users\/{user_id}&#xff0c;HTTP \u65b9\u6cd5\u4e3a PUT<br \/>\n# \u51fd\u6570 update_users \u63a5\u6536\u4e00\u4e2a User \u5b9e\u4f8b\u4f5c\u4e3a\u53c2\u6570&#xff0c;\u5c06\u5176\u6dfb\u52a0\u5230 users_list \u5217\u8868\u4e2d&#xff0c;\u5e76\u8fd4\u56de\u8be5\u5b9e\u4f8b<br \/>\n&#064;app.put(path&#061;&#034;\/users\/{user_id}&#034;,response_model&#061;User)<br \/>\ndef update_users(user_id:int,user:User):<br \/>\n    for u in users_list:<br \/>\n        if u.id &#061;&#061; user_id:<br \/>\n            u.name &#061; user.name<br \/>\n            u.email &#061; user.email<br \/>\n            return u<br \/>\n    return {&#034;error&#034;: &#034;User not found&#034;}<\/p>\n<p># \u5b9a\u4e49DELETE\u8bf7\u6c42<br \/>\n# \u5220\u9664\u7528\u6237<br \/>\n# \u8bf7\u6c42\u6a21\u578b\u4e3a User&#xff0c;\u54cd\u5e94\u6a21\u578b\u4e5f\u4e3a User   (\u63d0\u4ea4\u7684\u6570\u636e\u683c\u5f0f\u5fc5\u987b\u4e3a User \u6a21\u578b\u7684\u683c\u5f0f)<br \/>\n# \u8def\u5f84\u4e3a \/users\/{user_id}&#xff0c;HTTP \u65b9\u6cd5\u4e3a DELETE<br \/>\n# \u51fd\u6570 delete_users \u63a5\u6536\u4e00\u4e2a User \u5b9e\u4f8b\u4f5c\u4e3a\u53c2\u6570&#xff0c;\u5c06\u5176\u4ece users_list \u5217\u8868\u4e2d\u5220\u9664&#xff0c;\u5e76\u8fd4\u56de\u8be5\u5b9e\u4f8b<br \/>\n&#064;app.delete(path&#061;&#034;\/users\/{user_id}&#034;,response_model&#061;User)<br \/>\ndef delete_users(user_id:int):<br \/>\n    for u in users_list:<br \/>\n        if u.id &#061;&#061; user_id:<br \/>\n            users_list.remove(u)<br \/>\n            return u<br \/>\n    return {&#034;error&#034;: &#034;User not found&#034;}<\/p>\n<p>#\u670d\u52a1\u5668\u542f\u52a8\u5668<br \/>\n# \u5f53\u76f4\u63a5\u8fd0\u884c\u8be5\u811a\u672c\u65f6&#xff0c;\u542f\u52a8 FastAPI \u5e94\u7528<br \/>\n# \u76d1\u542c\u4e3b\u673a\u4e3a 127.0.0.1&#xff0c;\u7aef\u53e3\u4e3a 8001<br \/>\nif __name__ &#061;&#061; &#034;__main__&#034;:<br \/>\n    import uvicorn<br \/>\n    uvicorn.run(app, host&#061;&#034;127.0.0.1&#034;, port&#061;8001) <\/p>\n<h3>4.\u8fd0\u884c\u5c55\u793a<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"115\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260117003445-696ad92531be0.png\" width=\"712\" \/><\/p>\n<p>\u6700\u4e0b\u65b9\u4e3aURL&#xff0c;\u70b9\u51fb\u94fe\u63a5\u8df3\u8f6c\u672c\u5730\u6d4f\u89c8\u5668&#xff1b;<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"754\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260117003445-696ad9253d27e.png\" width=\"901\" \/><\/p>\n<p>\u56e0\u4e3a\u6211\u4eec\u5e76\u6ca1\u6709\u5728129.0.0.1:8000\u8fd9\u4e2aURL\u914d\u7f6e\u4efb\u4f55\u4e1c\u897f&#xff0c;\u4f7f\u7528\u5bf9\u4e8efastapi\u8fd9\u4e2a\u6a21\u7248\u4f1a\u7ed9\u4f60\u8fd4\u56dejosn\u683c\u5f0f\u7684<\/p>\n<p> {<br \/>\n  &#034;detail&#034;: &#034;Not Found&#034;<br \/>\n} <\/p>\n<p>\u540e\u53f0\u53cd\u9988&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"151\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260117003445-696ad92578019.png\" width=\"673\" \/><\/p>\n<p>\u4e0b\u4e00\u6b65\u6211\u4eec\u8bbf\u95ee\u6211\u4eec\u5b9a\u4e49\u8fc7\u7684&#xff1a;127.0.0.1:8000\/users<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"754\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260117003445-696ad92588730.png\" width=\"901\" \/><\/p>\n<p>[<br \/>\n  {<br \/>\n    &#034;name&#034;: &#034;\u5f20\u4e09&#034;,<br \/>\n    &#034;id&#034;: 1,<br \/>\n    &#034;email&#034;: &#034;zhangsan&#064;example.com&#034;<br \/>\n  },<br \/>\n  {<br \/>\n    &#034;name&#034;: &#034;\u674e\u56db&#034;,<br \/>\n    &#034;id&#034;: 2,<br \/>\n    &#034;email&#034;: &#034;lisi&#064;example.com&#034;<br \/>\n  },<br \/>\n  {<br \/>\n    &#034;name&#034;: &#034;\u738b\u4e94&#034;,<br \/>\n    &#034;id&#034;: 3,<br \/>\n    &#034;email&#034;: &#034;wangwu&#064;example.com&#034;<br \/>\n  }<br \/>\n] <\/p>\n<p>\u00a0\u540e\u53f0\u53cd\u9988&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"151\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260117003445-696ad92578019.png\" width=\"673\" \/><\/p>\n<p>\u4e0a\u9762\u76f8\u5f53\u4e8e\u8fd0\u884c\u4ee3\u7801\u7684\u8bf7\u6c42\u90e8\u5206&#xff1a;<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"352\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260117003445-696ad925bec52.png\" width=\"577\" \/><\/p>\n<h3>5.\u5411\u670d\u52a1\u5668\u53d1\u9001\u4e00\u4e2apost\u8bf7\u6c42<\/h3>\n<p>\u4e0b\u9762\u6211\u4eec\u51c6\u5907\u6267\u884cpost\u64cd\u4f5c&#xff0c;\u9996\u5148\u6267\u884cpost\u6211\u4eec\u7684\u6d4f\u89c8\u5668\u662f\u4e0d\u652f\u6301\u8fd9\u79cd\u64cd\u4f5c&#xff0c;\u9700\u8981\u501f\u52a9\u4e09\u65b9\u5de5\u5177&#xff1a;<\/p>\n<p>postman&#xff1b;<\/p>\n<p>\u56e0\u6b64\u6211\u5728\u7f51\u4e0a\u627e\u5230\u4e00\u4e2a\u5728\u7ebf\u5de5\u5177&#xff1a;\u5728\u7ebfHttp\u63a5\u53e3\u8c03\u8bd5\u5de5\u5177 | \u5728\u7ebfpostman\u5de5\u5177<\/p>\n<p>\u4e0b\u9762\u662f\u6211\u4ee3\u7801\u7684post\u8bf7\u6c42\u8bbe\u8ba1&#xff1a;<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"213\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260117003445-696ad925d6739.png\" width=\"714\" \/><\/p>\n<p>\u4ee5\u53ca\u63a5\u6536\u6570\u636e\u683c\u5f0f&#xff1a;<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"144\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260117003445-696ad925eb0b2.png\" width=\"277\" \/><\/p>\n<p>\u5728\u7ebf\u5de5\u5177\u9875\u9762&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"894\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260117003446-696ad92601053.png\" width=\"1333\" \/><\/p>\n<p><span style=\"background-color:#a2e043\">\u64cd\u4f5c\u91cd\u70b9&#xff1a;<\/span><\/p>\n<p>1.\u5c06\u8bf7\u6c42\u65b9\u5f0f\u8f6c\u6362\u6210post\u8bf7\u6c42<\/p>\n<p>2.\u8f93\u5165\u5bf9\u5e94URL\u53ca\u8def\u5f84<\/p>\n<p>3.\u9009\u62e9application\u4e0b\u7684josn\u683c\u5f0f<\/p>\n<p>4.\u6570\u636e\u683c\u5f0f\u5fc5\u987b\u6309\u7167\u5b9a\u4e49\u7684\u6765<\/p>\n<p>\u5982\u56fe&#xff1a;<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"894\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260117003446-696ad9268a500.png\" width=\"1333\" \/><\/p>\n<p>\u70b9\u51fb\u53d1\u9001&#xff1a;<\/p>\n<p>\u51fa\u73b0\u5982\u4e0b\u62a5\u9519&#xff1a;<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"168\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260117003446-696ad926f3c31.png\" width=\"575\" \/><\/p>\n<p>\u670d\u52a1\u5668\u7aef&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"133\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260117003447-696ad9270cd2f.png\" width=\"712\" \/><\/p>\n<p>\u9519\u8bef\u542b\u4e49<\/p>\n<p>&#8211; OPTIONS \/users &#xff1a;\u6d4f\u89c8\u5668\u53d1\u9001\u4e86\u4e00\u4e2aOPTIONS\u7c7b\u578b\u7684HTTP\u8bf7\u6c42\u5230\/users\u7aef\u70b9 &#8211; 405 Method Not Allowed &#xff1a;\u670d\u52a1\u5668\u4e0d\u5141\u8bb8\u4f7f\u7528OPTIONS\u65b9\u6cd5\u8bbf\u95ee\u8be5\u7aef\u70b9<\/p>\n<p><span style=\"background-color:#a2e043\">\u4f5c\u8005\u63d0\u95ee&#xff1a;<\/span>\u4e3a\u4ec0\u4e48\u4f1a\u53d1\u751f\u8fd9\u4e2a\u9519\u8bef&#xff1f;<\/p>\n<p>\u8fd9\u662f CORS&#xff08;\u8de8\u57df\u8d44\u6e90\u5171\u4eab&#xff09; \u673a\u5236\u5bfc\u81f4\u7684&#xff1a;<\/p>\n<p>1. \u5f53\u6d4f\u89c8\u5668\u4ece\u4e00\u4e2a\u57df\u540d&#xff08;\u5982 http:\/\/localhost:3000 &#xff09;\u8bbf\u95ee\u53e6\u4e00\u4e2a\u57df\u540d&#xff08;\u5982http:\/\/127.0.0.1:8001&#xff09;\u7684API\u65f6 2. \u6d4f\u89c8\u5668\u4f1a\u5148\u53d1\u9001\u4e00\u4e2a \u9884\u68c0\u8bf7\u6c42&#xff08;OPTIONS\u8bf7\u6c42&#xff09; \u6765\u68c0\u67e5\u670d\u52a1\u5668\u662f\u5426\u5141\u8bb8\u8de8\u57df\u8bbf\u95ee 3. \u5982\u679c\u670d\u52a1\u5668\u6ca1\u6709\u914d\u7f6eCORS\u6216\u6ca1\u6709\u5904\u7406OPTIONS\u8bf7\u6c42&#xff0c;\u5c31\u4f1a\u8fd4\u56de405\u9519\u8bef<\/p>\n<p>\u89e3\u51b3\u65b9\u6848&#xff1a;\u5728FastAPI\u4e2d\u6dfb\u52a0CORS\u652f\u6301<\/p>\n<p># \u914d\u7f6eCORS<\/p>\n<p>app.add_middleware(<\/p>\n<p>\u00a0 \u00a0 CORSMiddleware,<\/p>\n<p>\u00a0 \u00a0 allow_origins&#061;[&#034;*&#034;], \u00a0# \u5141\u8bb8\u6240\u6709\u6765\u6e90&#xff0c;\u751f\u4ea7\u73af\u5883\u5e94\u9650\u5236\u5177\u4f53\u57df\u540d<\/p>\n<p>\u00a0 \u00a0 allow_credentials&#061;True,<\/p>\n<p>\u00a0 \u00a0 allow_methods&#061;[&#034;*&#034;], \u00a0# \u5141\u8bb8\u6240\u6709HTTP\u65b9\u6cd5<\/p>\n<p>\u00a0 \u00a0 allow_headers&#061;[&#034;*&#034;], \u00a0# \u5141\u8bb8\u6240\u6709\u8bf7\u6c42\u5934<\/p>\n<p>)<\/p>\n<p>\u914d\u7f6e\u8bf4\u660e<\/p>\n<p>&#8211; allow_origins : \u6307\u5b9a\u5141\u8bb8\u7684\u57df\u540d&#xff0c; [&#034;*&#034;] \u8868\u793a\u5141\u8bb8\u6240\u6709\u57df\u540d &#8211; allow_credentials : \u662f\u5426\u5141\u8bb8\u53d1\u9001cookie &#8211; allow_methods : \u6307\u5b9a\u5141\u8bb8\u7684HTTP\u65b9\u6cd5 &#8211; allow_headers : \u6307\u5b9a\u5141\u8bb8\u7684\u8bf7\u6c42\u5934<\/p>\n<p>\u6548\u679c&#xff1a;\u6dfb\u52a0CORS\u4e2d\u95f4\u4ef6\u540e&#xff1a;<\/p>\n<p>&#8211; \u6d4f\u89c8\u5668\u7684OPTIONS\u9884\u68c0\u8bf7\u6c42\u4f1a\u5f97\u5230\u6b63\u786e\u54cd\u5e94 &#8211; \u8de8\u57df\u8bf7\u6c42&#xff08;\u5982\u4eceReact\/Vue\u524d\u7aef\u8c03\u7528API&#xff09;\u4f1a\u6b63\u5e38\u5de5\u4f5c &#8211; \u4e0d\u518d\u51fa\u73b0405 Method Not Allowed\u9519\u8bef<\/p>\n<p> \u6ce8\u610f\u4e8b\u9879<\/p>\n<p>&#8211; \u5728\u751f\u4ea7\u73af\u5883\u4e2d&#xff0c;\u4e0d\u8981\u4f7f\u7528 allow_origins&#061;[&#034;*&#034;] &#xff0c;\u5e94\u8be5\u6307\u5b9a\u5177\u4f53\u5141\u8bb8\u7684\u57df\u540d &#8211; \u53ea\u5f00\u653e\u5fc5\u8981\u7684\u65b9\u6cd5\u548c\u5934\u4fe1\u606f&#xff0c;\u9075\u5faa\u6700\u5c0f\u6743\u9650\u539f\u5219<\/p>\n<p>\u6dfb\u52a0\u540e\u5e76\u4e14\u5bfc\u5165\u76f8\u5173\u5e93\u91cd\u542f\u670d\u52a1\u5668&#xff1a;<\/p>\n<p>from fastapi.middleware.cors import CORSMiddleware <\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"385\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260117003447-696ad9271adda.png\" width=\"539\" \/><\/p>\n<p>ok&#xff0c;\u518d\u6b21\u53d1\u9001post\u8bf7\u6c42&#xff1a;<\/p>\n<p>postman\u51fa\u73b0\u5982\u4e0b\u62a5\u9519&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"894\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260117003447-696ad9272df90.png\" width=\"1333\" \/><\/p>\n<p>\u670d\u52a1\u5668\u540e\u53f0\u6ca1\u6709\u62a5\u9519<\/p>\n<p>\u5e94\u8be5\u662f\u683c\u5f0f\u6709\u95ee\u9898&#xff0c;\u91cd\u65b0\u6362\u683c\u5f0f&#xff0c;\u4e0d\u8981\u4e2d\u6587\u7684\u53cc\u5f15\u53f7&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"130\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260117003447-696ad92794509.png\" width=\"740\" \/><\/p>\n<p>\u6210\u529f\u53d1\u9001&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"894\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260117003447-696ad927a2fb1.png\" width=\"1333\" \/><\/p>\n<p>\u670d\u52a1\u5668\u540e\u53f0\u6ca1\u6709\u53d8\u5316&#xff1a;<\/p>\n<p>\u54b1\u4eec\u518d\u6b21\u56de\u5230\u67e5\u8be2\u9875\u9762\u770b\u6570\u636e\u662f\u5426\u63d0\u4ea4\u7ed9\u670d\u52a1\u5668<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"894\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260117003448-696ad9281c6d6.png\" width=\"1333\" \/><\/p>\n<p>\u5b8c\u7f8e&#xff0c;perfect&#xff01;&#xff01;<\/p>\n<h3>6.\u5411\u670d\u52a1\u5668\u53d1\u9001\u4e00\u4e2a\u5220\u9664\u8bf7\u6c42delete<\/h3>\n<p>\u6765\u5230postman\u9875\u9762\u7f16\u8f91URL\u5730\u5740\u4e3a127.0.0.1:8001\/users\/1<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"894\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260117003448-696ad928863ea.png\" width=\"1256\" \/><\/p>\n<p>\u70b9\u51fb\u53d1\u9001<\/p>\n<p>postman\u9875\u9762&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"894\" src=\"2026-01-17l3iqtbhdcmo.png\" width=\"1256\" \/><\/p>\n<p>\u518d\u7528postman\u53d1\u9001\u67e5\u8be2\u8bf7\u6c42<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"894\" src=\"2026-01-17zmdjh4y0fxv.png\" width=\"1256\" \/><\/p>\n<p>\u70b9\u51fb\u53d1\u9001<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"894\" src=\"2026-01-173jfyzgis4tv.png\" width=\"1256\" \/><\/p>\n<p>OK&#xff0c;\u6570\u636e&#xff08;id&#061;1\u7684\u6570\u636e\u88ab\u5220\u9664&#xff09;<\/p>\n<h3>7.\u5411\u670d\u52a1\u5668\u53d1\u9001\u4e00\u4e2a\u4fee\u6539\u7684\u8bf7\u6c42\u65b9\u5f0f&#xff08;put&#xff09;<\/h3>\n<p>\u76f8\u5e94\u4ee3\u7801&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"805\" src=\"2026-01-17hmo13uinmev.png\" width=\"1437\" \/><\/p>\n<p>\u539f\u59cb\u6570\u636e <img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"894\" src=\"2026-01-17yohl5mwvfej.png\" width=\"1102\" \/><\/p>\n<p>\u6211\u73b0\u5728\u8981\u628a\u5218\u5fb7\u534e\u7684\u90ae\u7bb1\u6539\u6210888<\/p>\n<p>\u6253\u5f00postman\u5c06URL\u4fee\u6539\u8fd8\u6709\u8bf7\u6c42\u4f53<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"894\" src=\"2026-01-17abdza2rmkdl.png\" width=\"1102\" \/><\/p>\n<p>\u70b9\u51fb\u53d1\u9001\u6210\u529f<\/p>\n<p>\u518d\u7528postman\u67e5\u8be2\u53ef\u5f97<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"894\" src=\"2026-01-1703geqfi4enh.png\" width=\"1102\" \/><\/p>\n<p>\u6210\u529f&#xff0c;perfect&#xff01;&#xff01;<\/p>\n<h3>8.\u54b1\u4eec\u8bbf\u95ee\u670d\u52a1\u5668\u7684\u5ba2\u6237\u7aef\u6709\u51e0\u4e2a&#xff1f;<\/h3>\n<p>\u4e24\u4e2a&#xff1a;<\/p>\n<p>\u6211\u4eec\u6d4f\u89c8\u5668\u548cpostman\u8fd9\u4e24\u4e2a\u5ba2\u6237\u7aef<\/p>\n<p><span style=\"background-color:#a2e043\">\u4f5c\u8005\u63d0\u95ee&#xff1a;<\/span>\u8fd8\u6709\u5417&#xff0c;\u8fd8\u6709\u5176\u4ed6\u7684\u65b9\u5f0f\u8bbf\u95ee\u6211\u7684\u670d\u52a1\u5668\u5417<\/p>\n<p>\u6211\u7684\u670d\u52a1\u5668\u662f\u53ef\u4ee5\u5206\u8fa8\u662f\u4ec0\u4e48\u5ba2\u6237\u7aef\u53d1\u7684\u8bf7\u6c42&#xff1a;\u5728\u8bf7\u6c42\u6295\u5934\u4e2d\u6709\u4e00\u53c2\u6570&#xff1a;User-Agent&#xff1a;\u6211\u662f\u8c01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"894\" src=\"2026-01-17styrh1cdpi3.png\" width=\"1253\" \/><\/p>\n<p>\u5982\u679c\u4f60\u7528\u722c\u866b&#xff0c;\u4f60\u80fd\u5728User-Agent\u8fd9\u4e2a\u5730\u65b9\u76f4\u63a5\u8bf4\u6211\u662f\u6252\u624b\u5417&#xff0c;\u6240\u4ee5\u722c\u866b\u9700\u8981\u4f2a\u88c5\u6210\u6d4f\u89c8\u5668\u5bf9\u670d\u52a1\u5668\u53d1\u8d77\u8bf7\u6c42\u83b7\u5f97\u81ea\u5df1\u60f3\u8981\u7684\u8d44\u6e90\u3002<\/p>\n<p>curl&#xff1a;\u53ef\u4ee5\u5411\u670d\u52a1\u5668\u53d1\u9001\u8bf7\u6c42&#xff08;\u64cd\u4f5c\u7cfb\u7edf\u81ea\u5e26\u7684&#xff09;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"499\" src=\"2026-01-17pdai5wxad0c.png\" width=\"979\" \/><\/p>\n<p><span style=\"background-color:#a2e043\">\u4f5c\u8005\u63d0\u95ee&#xff1a;<\/span>curl\u662f\u5426\u7ec4\u5305\u5411\u670d\u52a1\u5668\u53d1\u5305\u3002<\/p>\n<p>\u5411\u7ec8\u7aef\u8f93\u5165&#xff1a;<\/p>\n<p>url -i http:\/\/127.0.0.1:8000\/users <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"499\" src=\"2026-01-17oqoliznomhz.png\" width=\"979\" \/><\/p>\n<p>\u8fd4\u56de\u4e86\u4e00\u4e2a\u5b8c\u6574\u7684\u54cd\u5e94\u547d\u4ee4&#xff1a;\u54cd\u5e94\u4f53&#043;\u54cd\u5e94\u5934&#043;\u72b6\u6001\u884c<\/p>\n<p>\u6709\u70b9\u610f\u601d&#xff01;<\/p>\n<p>\u5728\u7ec8\u7aef\u7528curl\u9700\u8981\u4f7f\u7528\u5b8c\u6574\u7684\u8bf7\u6c42\u5305&#xff0c;\u8be6\u60c5\u8bf7\u4e0a\u7f51\u76f4\u63a5\u641c&#xff1b;<\/p>\n<h3>9.API\u6587\u6863<\/h3>\n<p>\u5bf9\u4e8e\u524d\u540e\u7aef\u5206\u79bb&#xff1a;\u9700\u8981\u7528API\u5f00\u53d1\u6587\u6863\u8fdb\u884c\u524d\u540e\u7aef\u6570\u636e\u4ea4\u6d41\u3002<\/p>\n<p>\u4e4b\u524d\u624b\u5199&#xff0c;\u73b0\u5728FastAPI\u63d0\u4f9bAPI\u5f00\u53d1\u6587\u6863.<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"37\" src=\"2026-01-17skemkero40j.png\" width=\"536\" \/><\/p>\n<p>\u8bbf\u95ee&#xff1a;<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"131\" src=\"2026-01-17bpawhs2pxcm.png\" width=\"546\" \/><\/p>\n<p><span class=\"link-card-box\"><span class=\"link-title\">\u00a0 \u00a0\u7f51\u5740&#xff1a;http:\/\/127.0.0.1:8000\/docs<\/span><span class=\"link-link\"><img decoding=\"async\" class=\"link-link-icon\" src=\"2026-01-17zhxxabbgde4.png\" \/>http:\/\/127.0.0.1:8000\/docs<\/span><\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"894\" src=\"2026-01-17pen2b2syadh.png\" width=\"1333\" \/><\/p>\n<p><span class=\"link-card-box\"><span class=\"link-title\">\u7b80\u5355FastAPI\u793a\u4f8b &#8211; ReDoc<\/span><span class=\"link-link\"><img decoding=\"async\" class=\"link-link-icon\" src=\"2026-01-17zhxxabbgde4.png\" \/>http:\/\/127.0.0.1:8000\/redoc<\/span><\/span><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"894\" src=\"2026-01-17ti5vf2i1muf.png\" width=\"1333\" \/><\/p>\n<p>\u53ef\u4ee5\u76f4\u63a5\u5728\u7f51\u7ad9\u4e0a\u8fdb\u884c\u6570\u636e\u8bf7\u6c42&#xff0c;\u4ea4\u4e92\u5f0f\u7684&#xff0c;\u5c31\u53ef\u4ee5\u4e0d\u7528postman\u548ccurl\u3002\u975e\u5e38\u725b\u903c\u3002<\/p>\n<p>\u4e24\u4e2a\u90fd\u53ef\u4ee5\u76f4\u63a5\u7528&#xff0c;\u4e0d\u662f\u6240\u6709\u7684\u90fd\u6709&#xff0c;\u8fd9\u5c31\u662fFastAPI\u76ee\u524d\u8fd9\u4e48\u53d7\u6b22\u8fce\u7684\u539f\u56e0\u3002<\/p>\n<h2>\u4e03\u3001\u9762\u8bd5\u4e60\u9898<\/h2>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\"><span style=\"color:#0000ff\">\u4e00\u3001\u9009\u62e9\u9898<\/span><\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">1. \u5728Python\u4e2d&#xff0c;\u54ea\u4e2a\u5e93\u7528\u4e8e\u6784\u5efaAPI\u63a5\u53e3&#xff1f;<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u00a0\u00a0\u00a0\u7b54\u6848&#xff1a;D. \u4ee5\u4e0a\u90fd\u662f<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">2. \u4ee5\u4e0b\u54ea\u4e2aHTTP\u65b9\u6cd5\u7528\u4e8e\u83b7\u53d6\u8d44\u6e90&#xff1f;<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u00a0\u00a0\u00a0\u7b54\u6848&#xff1a;A. GET<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">3. \u5728FastAPI\u4e2d&#xff0c;\u5982\u4f55\u5b9a\u4e49\u4e00\u4e2aGET\u8bf7\u6c42\u7684\u8def\u7531&#xff1f;<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u00a0\u00a0\u00a0\u7b54\u6848&#xff1a;D. &#064;app.get(&#034;\/path&#034;)<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">4. \u5728FastAPI\u4e2d&#xff0c;\u5982\u4f55\u83b7\u53d6\u8bf7\u6c42\u7684JSON\u6570\u636e&#xff1f;<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u00a0\u00a0\u00a0\u7b54\u6848&#xff1a;D. request.json()<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">5. \u4ee5\u4e0b\u54ea\u4e2a\u72b6\u6001\u7801\u8868\u793a\u8bf7\u6c42\u6210\u529f&#xff1f;<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u00a0\u00a0\u00a0\u7b54\u6848&#xff1a;A. 200<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u4e8c\u3001\u5224\u65ad\u9898<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">1. FastAPI\u662f\u4e00\u4e2a\u7528\u4e8e\u6784\u5efaAPI\u63a5\u53e3\u7684Python\u6846\u67b6\u3002&#xff08;\u5bf9\/\u9519&#xff09;<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u00a0\u00a0\u00a0\u7b54\u6848&#xff1a;\u5bf9<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">2. \u5728FastAPI\u4e2d&#xff0c;\u8def\u7531\u51fd\u6570\u7684\u8fd4\u56de\u503c\u4f1a\u81ea\u52a8\u8f6c\u6362\u4e3aJSON\u683c\u5f0f\u3002&#xff08;\u5bf9\/\u9519&#xff09;<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u00a0\u00a0\u00a0\u7b54\u6848&#xff1a;\u5bf9<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">3. FastAPI\u652f\u6301\u81ea\u52a8\u751f\u6210OpenAPI\u6587\u6863\u3002&#xff08;\u5bf9\/\u9519&#xff09;<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u00a0\u00a0\u00a0\u7b54\u6848&#xff1a;\u5bf9<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">4. \u5728FastAPI\u4e2d&#xff0c;&#064;app.post(&#034;\/path&#034;)\u7528\u4e8e\u5b9a\u4e49\u4e00\u4e2aPOST\u8bf7\u6c42\u7684\u8def\u7531\u3002&#xff08;\u5bf9\/\u9519&#xff09;<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u00a0\u00a0\u00a0\u7b54\u6848&#xff1a;\u9519&#xff0c;\u5e94\u4e3a&#064;app.post(&#034;\/path&#034;)\u800c\u4e0d\u662f&#064;app.post(&#034;\/path&#034;, methods&#061;[&#034;POST&#034;])<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">5. FastAPI\u4e0d\u652f\u6301\u5f02\u6b65\u7f16\u7a0b\u3002&#xff08;\u5bf9\/\u9519&#xff09;<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u00a0\u00a0\u00a0\u7b54\u6848&#xff1a;\u9519<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\"><span style=\"color:#0000ff\">\u4e09\u3001\u7b80\u7b54\u9898<\/span><\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">1. \u7b80\u8ff0FastAPI\u7684\u4f18\u52bf\u548c\u7279\u70b9\u3002<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u00a0\u00a0\u00a0&#8211; \u57fa\u4e8e\u6807\u51c6Python\u7c7b\u578b\u63d0\u793a\u3002<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u00a0\u00a0\u00a0&#8211; \u652f\u6301\u5f02\u6b65\u8bf7\u6c42\u5904\u7406\u3002<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u00a0\u00a0\u00a0&#8211; \u81ea\u52a8\u9a8c\u8bc1\u548c\u6587\u6863&#xff08;OpenAPI\u548cJSON Schema&#xff09;\u3002<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u00a0\u00a0\u00a0&#8211; \u57fa\u4e8eStarlette\u548cPydantic\u3002<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u00a0\u00a0\u00a0&#8211; \u6027\u80fd\u4f18\u5f02&#xff0c;\u4e0eNodeJS\u548cGo\u76f8\u5f53\u3002<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u00a0\u00a0\u00a0&#8211; \u7b80\u5355\u3001\u5feb\u901f\u3001\u5b89\u5168\u3002<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">2. \u5728FastAPI\u4e2d&#xff0c;\u5982\u4f55\u5b9a\u4e49\u8bf7\u6c42\u4f53\u7684\u6a21\u578b&#xff1f;<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u00a0\u00a0\u00a0&#8211; \u4f7f\u7528Pydantic\u6a21\u578b\u5b9a\u4e49\u8bf7\u6c42\u4f53\u7684\u7ed3\u6784&#xff0c;\u5e76\u4f7f\u7528&#096;Body&#096;\u53c2\u6570\u4ece\u8bf7\u6c42\u4e2d\u63d0\u53d6\u6570\u636e\u3002<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u00a0\u00a0\u00a0\u793a\u4f8b\u4ee3\u7801&#xff1a; \u00a0\u00a0<\/p>\n<p>\u00a0from pydantic import BaseModel<\/p>\n<p>\u00a0\u00a0\u00a0from fastapi import FastAPI, HTTPException<\/p>\n<p>\u00a0\u00a0\u00a0app &#061; FastAPI()<\/p>\n<p>\u00a0\u00a0\u00a0class Item(BaseModel):<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0name: str<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0description: str &#061; None<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0price: float<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0tax: float &#061; None<\/p>\n<p>\u00a0\u00a0\u00a0&#064;app.post(&#034;\/items\/&#034;)<\/p>\n<p>\u00a0\u00a0\u00a0async def create_item(item: Item):<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return item <\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">3. \u5982\u4f55\u5728FastAPI\u4e2d\u5904\u7406\u67e5\u8be2\u53c2\u6570\u548c\u8def\u5f84\u53c2\u6570&#xff1f;<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u00a0\u00a0\u00a0&#8211; \u4f7f\u7528\u51fd\u6570\u53c2\u6570\u548c\u7c7b\u578b\u6ce8\u89e3\u6765\u5b9a\u4e49\u8def\u5f84\u53c2\u6570\u548c\u67e5\u8be2\u53c2\u6570\u3002<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u00a0\u00a0\u00a0\u793a\u4f8b\u4ee3\u7801&#xff1a;\u00a0<\/p>\n<p>&#064;app.get(&#034;\/items\/{item_id}&#034;)<\/p>\n<p>\u00a0\u00a0\u00a0async def read_item(item_id: int, q: str &#061; None):<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return {&#034;item_id&#034;: item_id, &#034;q&#034;: q} <\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">4. \u5982\u4f55\u5728FastAPI\u4e2d\u8fdb\u884c\u8bf7\u6c42\u6570\u636e\u7684\u9a8c\u8bc1&#xff1f;<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u00a0\u00a0\u00a0&#8211; \u901a\u8fc7Pydantic\u6a21\u578b\u81ea\u52a8\u9a8c\u8bc1\u8bf7\u6c42\u6570\u636e&#xff0c;\u4efb\u4f55\u4e0d\u7b26\u5408\u6a21\u578b\u7684\u6570\u636e\u90fd\u4f1a\u8fd4\u56de\u9519\u8bef\u3002<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u00a0\u00a0\u00a0\u793a\u4f8b\u4ee3\u7801&#xff1a;<\/p>\n<p>\u00a0\u00a0from pydantic import BaseModel, ValidationError<\/p>\n<p>\u00a0\u00a0\u00a0class Item(BaseModel):<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0name: str<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0price: float<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0is_offer: bool &#061; None<\/p>\n<p>\u00a0\u00a0\u00a0try:<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0item &#061; Item(**data)<\/p>\n<p>\u00a0\u00a0\u00a0except ValidationError as e:<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0raise HTTPException(status_code&#061;422, detail&#061;e.errors()) <\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">5. \u7b80\u8ff0FastAPI\u7684\u4f9d\u8d56\u6ce8\u5165\u673a\u5236\u3002<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u00a0\u00a0\u00a0&#8211; FastAPI\u5141\u8bb8\u4f7f\u7528\u4f9d\u8d56\u6ce8\u5165\u6765\u5904\u7406\u8bf7\u6c42\u524d\u548c\u8bf7\u6c42\u540e\u7684\u903b\u8f91&#xff0c;\u5982\u8ba4\u8bc1\u3001\u6570\u636e\u5e93\u4f1a\u8bdd\u7b49\u3002<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u00a0\u00a0\u00a0&#8211; \u901a\u8fc7\u5b9a\u4e49\u4f9d\u8d56\u51fd\u6570\u5e76\u5728\u8def\u7531\u51fd\u6570\u4e2d\u4f7f\u7528&#xff0c;\u53ef\u4ee5\u91cd\u7528\u4ee3\u7801\u5e76\u4fdd\u6301\u8def\u7531\u51fd\u6570\u7684\u7b80\u6d01\u3002<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u00a0\u00a0\u00a0&#8211; \u4f9d\u8d56\u53ef\u4ee5\u88ab\u7f13\u5b58&#xff0c;\u901a\u8fc7\u6dfb\u52a0&#096;Depends&#096;\u6765\u5b9e\u73b0\u3002<\/p>\n<p style=\"margin-left:.0001pt;margin-right:0;text-align:justify\">\u00a0\u00a0\u00a0\u793a\u4f8b\u4ee3\u7801&#xff1a;<\/p>\n<p>\u00a0\u00a0\u00a0from fastapi import Depends, HTTPException<\/p>\n<p>\u00a0\u00a0\u00a0def get_db():<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0db &#061; SessionLocal()<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0try:<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0yield db<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0finally:<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0db.close()<\/p>\n<p>\u00a0\u00a0\u00a0&#064;app.get(&#034;\/items\/&#034;)<\/p>\n<p>\u00a0\u00a0\u00a0async def read_items(db: Session &#061; Depends(get_db)):<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0items &#061; db.query(Item).all()<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return items<\/p>\n","protected":false},"excerpt":{"rendered":"<p>API&#xff08;Application Programming Interface&#xff09;\u662f\u4e0d\u540c\u8f6f\u4ef6\u7cfb\u7edf\u4e4b\u95f4\u7684\u901a\u4fe1\u63a5\u53e3&#xff0c;\u662f\u73b0\u4ee3\u8f6f\u4ef6\u67b6\u6784\u7684\u6838\u5fc3\u7ec4\u4ef6\u3002\u672c\u6587\u5c06\u4ece \u57fa\u7840\u6982\u5ff5\u5230\u5b9e\u9645\u5b9e\u73b0 &#xff0c;\u8be6\u7ec6\u8bb2\u89e3API\u5f00\u53d1\u7684\u5168\u6d41\u7a0b\u3002<br \/>\n\u4e00\u3001API\u57fa\u7840\u6982\u5ff5 1. \u4ec0\u4e48\u662fAPI&#xff1f; API\u662f\u4e00\u7ec4\u5b9a\u4e49\u7684\u89c4\u5219\u548c\u534f\u8bae&#xff0c;\u5141\u8bb8\u4e00\u4e2a\u8f6f\u4ef6\u7cfb\u7edf\u4e0e\u53e6\u4e00\u4e2a\u8f6f\u4ef6\u7cfb\u7edf\u4ea4\u4e92&#xff0c;\u800c\u65e0\u9700\u4e86\u89e3\u5176\u5185\u90e8\u5b9e\u73b0\u7ec6\u8282\u3002<br \/>\n\u4f8b\u5982&#xff1a; &#8211; \u5929\u6c14\u5e94\u7528\u901a\u8fc7\u5929\u6c14AP<\/p>\n","protected":false},"author":2,"featured_media":61210,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[72,151,2314,81,205,677,191],"topic":[],"class_list":["post-61230","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-fastapi","tag-http","tag-postman","tag-python","tag-tcp-ip","tag-677","tag-191"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u57fa\u4e8eFastAPI\u7684API\u5f00\u53d1\uff08\u722c\u866b\u7684\u5de5\u4f5c\u539f\u7406\uff0c\u670d\u52a1\u5668\u63a5\u53e3\u642d\u5efa\uff09\uff1a\u4ece\u8bbe\u8ba1\u5230\u90e8\u7f72\u8be6\u89e3+\u9762\u8bd5\u4e60\u9898 - \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\/61230.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u57fa\u4e8eFastAPI\u7684API\u5f00\u53d1\uff08\u722c\u866b\u7684\u5de5\u4f5c\u539f\u7406\uff0c\u670d\u52a1\u5668\u63a5\u53e3\u642d\u5efa\uff09\uff1a\u4ece\u8bbe\u8ba1\u5230\u90e8\u7f72\u8be6\u89e3+\u9762\u8bd5\u4e60\u9898 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"API&#xff08;Application Programming Interface&#xff09;\u662f\u4e0d\u540c\u8f6f\u4ef6\u7cfb\u7edf\u4e4b\u95f4\u7684\u901a\u4fe1\u63a5\u53e3&#xff0c;\u662f\u73b0\u4ee3\u8f6f\u4ef6\u67b6\u6784\u7684\u6838\u5fc3\u7ec4\u4ef6\u3002\u672c\u6587\u5c06\u4ece \u57fa\u7840\u6982\u5ff5\u5230\u5b9e\u9645\u5b9e\u73b0 &#xff0c;\u8be6\u7ec6\u8bb2\u89e3API\u5f00\u53d1\u7684\u5168\u6d41\u7a0b\u3002 \u4e00\u3001API\u57fa\u7840\u6982\u5ff5 1. \u4ec0\u4e48\u662fAPI&#xff1f; API\u662f\u4e00\u7ec4\u5b9a\u4e49\u7684\u89c4\u5219\u548c\u534f\u8bae&#xff0c;\u5141\u8bb8\u4e00\u4e2a\u8f6f\u4ef6\u7cfb\u7edf\u4e0e\u53e6\u4e00\u4e2a\u8f6f\u4ef6\u7cfb\u7edf\u4ea4\u4e92&#xff0c;\u800c\u65e0\u9700\u4e86\u89e3\u5176\u5185\u90e8\u5b9e\u73b0\u7ec6\u8282\u3002 \u4f8b\u5982&#xff1a; - \u5929\u6c14\u5e94\u7528\u901a\u8fc7\u5929\u6c14AP\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/61230.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-01-17T00:34:50+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260117003444-696ad924bd917.png\" \/>\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=\"6 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/61230.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/61230.html\",\"name\":\"\u57fa\u4e8eFastAPI\u7684API\u5f00\u53d1\uff08\u722c\u866b\u7684\u5de5\u4f5c\u539f\u7406\uff0c\u670d\u52a1\u5668\u63a5\u53e3\u642d\u5efa\uff09\uff1a\u4ece\u8bbe\u8ba1\u5230\u90e8\u7f72\u8be6\u89e3+\u9762\u8bd5\u4e60\u9898 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-01-17T00:34:50+00:00\",\"dateModified\":\"2026-01-17T00:34:50+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/61230.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/61230.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/61230.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u57fa\u4e8eFastAPI\u7684API\u5f00\u53d1\uff08\u722c\u866b\u7684\u5de5\u4f5c\u539f\u7406\uff0c\u670d\u52a1\u5668\u63a5\u53e3\u642d\u5efa\uff09\uff1a\u4ece\u8bbe\u8ba1\u5230\u90e8\u7f72\u8be6\u89e3+\u9762\u8bd5\u4e60\u9898\"}]},{\"@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":"\u57fa\u4e8eFastAPI\u7684API\u5f00\u53d1\uff08\u722c\u866b\u7684\u5de5\u4f5c\u539f\u7406\uff0c\u670d\u52a1\u5668\u63a5\u53e3\u642d\u5efa\uff09\uff1a\u4ece\u8bbe\u8ba1\u5230\u90e8\u7f72\u8be6\u89e3+\u9762\u8bd5\u4e60\u9898 - \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\/61230.html","og_locale":"zh_CN","og_type":"article","og_title":"\u57fa\u4e8eFastAPI\u7684API\u5f00\u53d1\uff08\u722c\u866b\u7684\u5de5\u4f5c\u539f\u7406\uff0c\u670d\u52a1\u5668\u63a5\u53e3\u642d\u5efa\uff09\uff1a\u4ece\u8bbe\u8ba1\u5230\u90e8\u7f72\u8be6\u89e3+\u9762\u8bd5\u4e60\u9898 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"API&#xff08;Application Programming Interface&#xff09;\u662f\u4e0d\u540c\u8f6f\u4ef6\u7cfb\u7edf\u4e4b\u95f4\u7684\u901a\u4fe1\u63a5\u53e3&#xff0c;\u662f\u73b0\u4ee3\u8f6f\u4ef6\u67b6\u6784\u7684\u6838\u5fc3\u7ec4\u4ef6\u3002\u672c\u6587\u5c06\u4ece \u57fa\u7840\u6982\u5ff5\u5230\u5b9e\u9645\u5b9e\u73b0 &#xff0c;\u8be6\u7ec6\u8bb2\u89e3API\u5f00\u53d1\u7684\u5168\u6d41\u7a0b\u3002 \u4e00\u3001API\u57fa\u7840\u6982\u5ff5 1. \u4ec0\u4e48\u662fAPI&#xff1f; API\u662f\u4e00\u7ec4\u5b9a\u4e49\u7684\u89c4\u5219\u548c\u534f\u8bae&#xff0c;\u5141\u8bb8\u4e00\u4e2a\u8f6f\u4ef6\u7cfb\u7edf\u4e0e\u53e6\u4e00\u4e2a\u8f6f\u4ef6\u7cfb\u7edf\u4ea4\u4e92&#xff0c;\u800c\u65e0\u9700\u4e86\u89e3\u5176\u5185\u90e8\u5b9e\u73b0\u7ec6\u8282\u3002 \u4f8b\u5982&#xff1a; - \u5929\u6c14\u5e94\u7528\u901a\u8fc7\u5929\u6c14AP","og_url":"https:\/\/www.wsisp.com\/helps\/61230.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-01-17T00:34:50+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260117003444-696ad924bd917.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"6 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/61230.html","url":"https:\/\/www.wsisp.com\/helps\/61230.html","name":"\u57fa\u4e8eFastAPI\u7684API\u5f00\u53d1\uff08\u722c\u866b\u7684\u5de5\u4f5c\u539f\u7406\uff0c\u670d\u52a1\u5668\u63a5\u53e3\u642d\u5efa\uff09\uff1a\u4ece\u8bbe\u8ba1\u5230\u90e8\u7f72\u8be6\u89e3+\u9762\u8bd5\u4e60\u9898 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-01-17T00:34:50+00:00","dateModified":"2026-01-17T00:34:50+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/61230.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/61230.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/61230.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u57fa\u4e8eFastAPI\u7684API\u5f00\u53d1\uff08\u722c\u866b\u7684\u5de5\u4f5c\u539f\u7406\uff0c\u670d\u52a1\u5668\u63a5\u53e3\u642d\u5efa\uff09\uff1a\u4ece\u8bbe\u8ba1\u5230\u90e8\u7f72\u8be6\u89e3+\u9762\u8bd5\u4e60\u9898"}]},{"@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\/61230","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=61230"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/61230\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/61210"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=61230"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=61230"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=61230"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=61230"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}