{"id":1380,"date":"2022-11-15T19:31:13","date_gmt":"2022-11-15T11:31:13","guid":{"rendered":"http:\/\/175.24.184.226\/?p=1380"},"modified":"2022-11-15T19:56:39","modified_gmt":"2022-11-15T11:56:39","slug":"fastapi%e5%9f%ba%e7%a1%80%e6%95%99%e7%a8%8b%e4%b8%8a","status":"publish","type":"post","link":"\/?p=1380","title":{"rendered":"fastapi\u57fa\u7840\u6559\u7a0b(\u4e0a)"},"content":{"rendered":"<h2>1.\u5b89\u88c5<\/h2>\n<p><strong>\u4f7f\u7528 FastAPI \u9700\u8981 Python \u7248\u672c\u5927\u4e8e\u7b49\u4e8e 3.6<\/strong><\/p>\n<p>\u5b89\u88c5\u5f88\u7b80\u5355\uff0c\u76f4\u63a5 <code>pip install fastapi<\/code> \u5373\u53ef\uff0c<\/p>\n<p>\u5e76\u4e14\u4f1a\u81ea\u52a8\u5b89\u88c5 Starlette \u548c Pydantic\u3002<\/p>\n<p>\u7136\u540e\u8fd8\u8981 <code>pip install uvicorn<\/code>\uff0c\u56e0\u4e3a uvicorn \u662f\u8fd0\u884c\u76f8\u5173\u5e94\u7528\u7a0b\u5e8f\u7684\u670d\u52a1\u5668\u3002\u6216\u8005\u4e00\u6b65\u5230\u4f4d\uff1a<\/p>\n<p><code>pip install fastapi[all]<\/code>\uff0c<\/p>\n<p>\u4f1a\u5c06\u6240\u6709\u4f9d\u8d56\u5168\u90e8\u5b89\u88c5\u3002<\/p>\n<h2>2.\u7b80\u5355\u8bf7\u6c42<\/h2>\n<p>\u7f16\u5199<code>main.py<\/code>:<\/p>\n<pre><code class=\"language-python\">from fastapi import FastAPI\nimport uvicorn\n\napp = FastAPI()\n\n@app.get(&quot;\/&quot;)\nasync def root():\n    return {&quot;message&quot;: &quot;Hello World&quot;}\n\n@app.get(&quot;\/hello\/{name}&quot;)\nasync def say_hello(name: str):\n    return {&quot;message&quot;: f&quot;Hello {name}&quot;}\n\nif __name__ == &#039;__main__&#039;:\n    uvicorn.run(&quot;main:app&quot;, host=&quot;0.0.0.0&quot;, port=5555)<\/code><\/pre>\n<p>\u7528pycharm\u81ea\u5efa\u7684\u9879\u76ee\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<pre><code class=\"language-python\">from fastapi import FastAPI\n\napp = FastAPI()\n\n@app.get(&quot;\/&quot;)\nasync def root():\n    return {&quot;message&quot;: &quot;Hello World&quot;}\n\n@app.get(&quot;\/hello\/{name}&quot;)\nasync def say_hello(name: str):\n    return {&quot;message&quot;: f&quot;Hello {name}&quot;}<\/code><\/pre>\n<p>\u5dee\u5728\u54ea\u5462\uff1f\u5c31\u662f<code>uvicorn<\/code>\u90e8\u5206\uff0c\u5176\u5b9e\u4e5f\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u884c\u542f\u52a8\u670d\u52a1,\u6548\u679c\u7c7b\u4f3c\uff1a<\/p>\n<pre><code class=\"language-shell\">uvicorn test:app --reload\n# \u6307\u5b9a\u7aef\u53e3\u542f\u52a8\nuvicorn test:app --host &#039;0.0.0.0&#039; --port 8000 --reload<\/code><\/pre>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/202211141445278.png\" alt=\"image-20221114144456033\" \/><\/p>\n<h3>2.1 \u4e0d\u540c\u7c7b\u578b\u7684\u8fd4\u56de\u503c<\/h3>\n<p>\u7f16\u5199test_main.http\u6d4b\u8bd5\u8bf7\u6c42\uff1a<\/p>\n<p><code>test_main.http:<\/code><\/p>\n<p><strong>1).int<\/strong><\/p>\n<pre><code class=\"language-http\"># Test your FastAPI endpoints\n\nGET http:\/\/127.0.0.1:5555\/str\nAccept: application\/json<\/code><\/pre>\n<pre><code class=\"language-shell\">http:\/\/127.0.0.1:5555\/int\n\nHTTP\/1.1 200 OK\ndate: Mon, 14 Nov 2022 06:51:58 GMT\nserver: uvicorn\ncontent-length: 3\ncontent-type: application\/json\n\n666\n\u54cd\u5e94\u6587\u4ef6\u5df2\u4fdd\u5b58\u3002\n> 2022-11-14T145159.200.json\n\nResponse code: 200 (OK); Time: 3ms (3 ms); Content length: 3 bytes (3 B)<\/code><\/pre>\n<p><strong>2).str<\/strong><\/p>\n<pre><code class=\"language-http\">GET http:\/\/127.0.0.1:5555\/str\nAccept: application\/json<\/code><\/pre>\n<pre><code class=\"language-shell\">http:\/\/127.0.0.1:5555\/str\n\nHTTP\/1.1 200 OK\ndate: Mon, 14 Nov 2022 06:53:25 GMT\nserver: uvicorn\ncontent-length: 14\ncontent-type: application\/json\n\n&quot;\u53e4\u660e\u5730\u89c9&quot;\n\u54cd\u5e94\u6587\u4ef6\u5df2\u4fdd\u5b58\u3002\n> 2022-11-14T145325.200.json\n\nResponse code: 200 (OK); Time: 1ms (1 ms); Content length: 6 bytes (6 B)<\/code><\/pre>\n<p><strong>3).bytes<\/strong><\/p>\n<pre><code class=\"language-http\">GET http:\/\/127.0.0.1:5555\/bytes\nAccept: application\/json<\/code><\/pre>\n<pre><code class=\"language-shell\">http:\/\/127.0.0.1:5555\/bytes\n\nHTTP\/1.1 200 OK\ndate: Mon, 14 Nov 2022 06:54:38 GMT\nserver: uvicorn\ncontent-length: 8\ncontent-type: application\/json\n\n&quot;satori&quot;\n\u54cd\u5e94\u6587\u4ef6\u5df2\u4fdd\u5b58\u3002\n> 2022-11-14T145439.200.json\n\nResponse code: 200 (OK); Time: 2ms (2 ms); Content length: 8 bytes (8 B)<\/code><\/pre>\n<p><strong>4).tuple<\/strong><\/p>\n<pre><code class=\"language-http\">GET http:\/\/127.0.0.1:5555\/tuple\nAccept: application\/json<\/code><\/pre>\n<pre><code class=\"language-shell\">http:\/\/127.0.0.1:5555\/tuple\n\nHTTP\/1.1 200 OK\ndate: Mon, 14 Nov 2022 06:55:34 GMT\nserver: uvicorn\ncontent-length: 49\ncontent-type: application\/json\n\n[\n  &quot;\u53e4\u660e\u5730\u89c9&quot;,\n  &quot;\u53e4\u660e\u5730\u604b&quot;,\n  &quot;\u96fe\u96e8\u9b54\u7406\u6c99&quot;\n]\n\u54cd\u5e94\u6587\u4ef6\u5df2\u4fdd\u5b58\u3002\n> 2022-11-14T145535.200.json\n\nResponse code: 200 (OK); Time: 3ms (3 ms); Content length: 23 bytes (23 B)<\/code><\/pre>\n<p><strong>5).list<\/strong><\/p>\n<pre><code class=\"language-http\">GET http:\/\/127.0.0.1:5555\/list\nAccept: application\/json<\/code><\/pre>\n<pre><code class=\"language-shell\">http:\/\/127.0.0.1:5555\/list\n\nHTTP\/1.1 200 OK\ndate: Mon, 14 Nov 2022 06:56:12 GMT\nserver: uvicorn\ncontent-length: 67\ncontent-type: application\/json\n\n[\n  {\n    &quot;name&quot;: &quot;\u53e4\u660e\u5730\u89c9&quot;,\n    &quot;age&quot;: 17\n  },\n  {\n    &quot;name&quot;: &quot;\u53e4\u660e\u5730\u604b&quot;,\n    &quot;age&quot;: 16\n  }\n]\n\u54cd\u5e94\u6587\u4ef6\u5df2\u4fdd\u5b58\u3002\n> 2022-11-14T145613.200.json\n\nResponse code: 200 (OK); Time: 2ms (2 ms); Content length: 51 bytes (51 B)<\/code><\/pre>\n<h3>2.2 \u52a8\u6001\u8def\u5f84<\/h3>\n<p>\u53ef\u4ee5\u770b\u5230\u57fa\u672c\u4e0a\u90fd\u662f\u652f\u6301\u7684\uff0c\u53ea\u4e0d\u8fc7\u5143\u7ec4\u81ea\u52a8\u8f6c\u6210\u5217\u8868\u8fd4\u56de\u4e86\u3002\u5e76\u4e14\u5f53\u524d\u7684\u8def\u5f84\u662f\u5199\u6b7b\u7684\uff0c\u5982\u679c\u6211\u4eec\u60f3\u52a8\u6001\u58f0\u660e\u8def\u5f84\u53c2\u6570\u8be5\u600e\u4e48\u505a\u5462\uff1f<\/p>\n<pre><code class=\"language-python\">from fastapi import FastAPI\nimport uvicorn\n\napp = FastAPI()\n\n@app.get(&quot;\/items\/{item_id}&quot;)\nasync def get_item(item_id):\n    &quot;&quot;&quot;\n    \u548c Flask \u4e0d\u540c\uff0cFlask \u662f\u4f7f\u7528 &lt;&gt;\n    \u800c FastAPI \u4f7f\u7528 {}\n    &quot;&quot;&quot;\n    return {&quot;item_id&quot;: item_id}\n\nif __name__ == &quot;__main__&quot;:\n    uvicorn.run(&quot;main:app&quot;, host=&quot;0.0.0.0&quot;, port=5555)<\/code><\/pre>\n<p>\u6d4b\u8bd5\u8def\u7531\uff1a<\/p>\n<pre><code class=\"language-http\">GET http:\/\/127.0.0.1:5555\/items\/1\nAccept: application\/json<\/code><\/pre>\n<pre><code class=\"language-shell\">http:\/\/127.0.0.1:5555\/items\/1\n\nHTTP\/1.1 200 OK\ndate: Mon, 14 Nov 2022 06:59:03 GMT\nserver: uvicorn\ncontent-length: 15\ncontent-type: application\/json\n\n{\n  &quot;item_id&quot;: &quot;1&quot;\n}\n\u54cd\u5e94\u6587\u4ef6\u5df2\u4fdd\u5b58\u3002\n> 2022-11-14T145903.200.json\n\nResponse code: 200 (OK); Time: 3ms (3 ms); Content length: 15 bytes (15 B)<\/code><\/pre>\n<h3>2.3 \u53c2\u6570\u7c7b\u578b\u9650\u5236<\/h3>\n<p>\u6574\u4f53\u975e\u5e38\u7b80\u5355\uff0c\u8def\u7531\u91cc\u9762\u7684\u8def\u5f84\u53c2\u6570\u53ef\u4ee5\u653e\u4efb\u610f\u4e2a\uff0c\u53ea\u662f {} \u91cc\u9762\u7684\u53c2\u6570\u5fc5\u987b\u8981\u5728\u89c6\u56fe\u51fd\u6570\u7684\u53c2\u6570\u4e2d\u51fa\u73b0\u3002\u4f46\u662f\u95ee\u9898\u6765\u4e86\uff0c\u6211\u4eec\u597d\u50cf\u6ca1\u6709\u89c4\u5b9a\u7c7b\u578b\u554a\uff0c\u5982\u679c\u6211\u4eec\u5e0c\u671b\u67d0\u4e2a\u8def\u5f84\u53c2\u6570\u53ea\u80fd\u63a5\u6536\u6307\u5b9a\u7684\u7c7b\u578b\u8981\u600e\u4e48\u505a\u5462\uff1f<\/p>\n<p>\u6b63\u786e\u7c7b\u578b\uff1a<\/p>\n<pre><code class=\"language-http\"># Test your FastAPI endpoints\n\nGET http:\/\/127.0.0.1:5555\/items\/111\nAccept: application\/json<\/code><\/pre>\n<pre><code class=\"language-shell\">http:\/\/127.0.0.1:5555\/items\/111\n\nHTTP\/1.1 200 OK\ndate: Mon, 14 Nov 2022 07:28:57 GMT\nserver: uvicorn\ncontent-length: 15\ncontent-type: application\/json\n\n{\n  &quot;item_id&quot;: 111\n}\n\u54cd\u5e94\u6587\u4ef6\u5df2\u4fdd\u5b58\u3002\n> 2022-11-14T152857.200.json\n\nResponse code: 200 (OK); Time: 1ms (1 ms); Content length: 15 bytes (15 B)<\/code><\/pre>\n<hr \/>\n<p>\u9519\u8bef\u7c7b\u578b\uff1a<\/p>\n<pre><code class=\"language-http\"># Test your FastAPI endpoints\n\nGET http:\/\/127.0.0.1:5555\/items\/qqq\nAccept: application\/json<\/code><\/pre>\n<pre><code class=\"language-shell\">http:\/\/127.0.0.1:5555\/items\/qqq\n\nHTTP\/1.1 422 Unprocessable Entity\ndate: Mon, 14 Nov 2022 07:27:37 GMT\nserver: uvicorn\ncontent-length: 104\ncontent-type: application\/json\n\n{\n  &quot;detail&quot;: [\n    {\n      &quot;loc&quot;: [\n        &quot;path&quot;,\n        &quot;item_id&quot;\n      ],\n      &quot;msg&quot;: &quot;value is not a valid integer&quot;,\n      &quot;type&quot;: &quot;type_error.integer&quot;\n    }\n  ]\n}\n\u54cd\u5e94\u6587\u4ef6\u5df2\u4fdd\u5b58\u3002\n> 2022-11-14T152738.422.json\n\nResponse code: 422 (Unprocessable Entity); Time: 3ms (3 ms); Content length: 104 bytes (104 B)<\/code><\/pre>\n<p>\u5982\u679c\u6211\u4eec\u4f20\u9012\u7684\u503c\u65e0\u6cd5\u8f6c\u6210\u6574\u578b\u7684\u8bdd\uff0c\u90a3\u4e48\u4f1a\u8fdb\u884c\u63d0\u793a\uff1a\u544a\u8bc9\u6211\u4eec value \u4e0d\u662f\u4e00\u4e2a\u6709\u6548\u7684\u6574\u578b\uff0c\u53ef\u4ee5\u770b\u5230\u7ed9\u7684\u63d0\u793a\u4fe1\u606f\u8fd8\u662f\u975e\u5e38\u6e05\u6670\u7684\u3002<\/p>\n<p>\u6240\u4ee5\u901a\u8fc7 Python \u7684\u7c7b\u578b\u58f0\u660e\uff0cFastAPI \u63d0\u4f9b\u4e86\u6570\u636e\u6821\u9a8c\u7684\u529f\u80fd\uff0c\u5f53\u6821\u9a8c\u4e0d\u901a\u8fc7\u7684\u65f6\u5019\u4f1a\u6e05\u695a\u5730\u6307\u51fa\u6ca1\u6709\u901a\u8fc7\u7684\u539f\u56e0\u3002\u5728\u6211\u4eec\u5f00\u53d1\u548c\u8c03\u8bd5\u7684\u65f6\u5019\uff0c\u8fd9\u4e2a\u529f\u80fd\u975e\u5e38\u6709\u7528\u3002<\/p>\n<h3>2.4 \u8def\u7531\u987a\u5e8f<\/h3>\n<p>\u6211\u4eec\u5728\u5b9a\u4e49\u8def\u7531\u7684\u65f6\u5019\u9700\u8981\u6ce8\u610f\u4e00\u4e0b\u987a\u5e8f\uff0c\u4e3e\u4e2a\u4f8b\u5b50\uff1a<\/p>\n<pre><code class=\"language-python\">from fastapi import FastAPI\nimport uvicorn\n\napp = FastAPI()\n\n@app.get(&quot;\/users\/me&quot;)\nasync def read_user_me():\n    return {&quot;user_id&quot;: &quot;the current user&quot;}\n\n@app.get(&quot;\/users\/{user_id}&quot;)\nasync def read_user(user_id: int):\n    return {&quot;user_id&quot;: user_id}\n\nif __name__ == &quot;__main__&quot;:\n    uvicorn.run(&quot;main:app&quot;, host=&quot;0.0.0.0&quot;, port=5555)<\/code><\/pre>\n<p>\u56e0\u4e3a\u8def\u5f84\u5339\u914d\u662f\u6309\u7167\u987a\u5e8f\u8fdb\u884c\u7684\uff0c\u6240\u4ee5\u8fd9\u91cc\u8981\u4fdd\u8bc1 <code>\/users\/me<\/code> \u5728<code>\/users\/{user_id}<\/code> \u7684\u524d\u9762\uff0c\u5426\u5219\u7684\u8bdd\u53ea\u4f1a\u5339\u914d\u5230 <code>\/users\/{user_id}<\/code>\uff0c\u8fd9\u6837\u7684\u8bdd\u8bbf\u95ee <code>\/users\/me<\/code> \u5c31\u4f1a\u89e3\u6790\u9519\u8bef\uff0c\u56e0\u4e3a\u5b57\u7b26\u4e32 &quot;me&quot; \u65e0\u6cd5\u89e3\u6790\u6210\u6574\u578b\u3002<\/p>\n<h2>3.\u4ea4\u4e92\u5f0f\u6587\u6863<\/h2>\n<p>FastAPI \u4f1a\u81ea\u52a8\u63d0\u4f9b\u4e00\u4e2a\u7c7b\u4f3c\u4e8e Swagger \u7684\u4ea4\u4e92\u5f0f\u6587\u6863\uff0c\u6211\u4eec\u8f93\u5165 localhost:5555\/docs \u5373\u53ef\u8fdb\u5165\u3002<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/202211141532448.png\" alt=\"image-20221114153247770\" \/><\/p>\n<p>\u81f3\u4e8e localhost:5555\/docs \u9875\u9762\u672c\u8eab\uff0c\u6211\u4eec\u4e5f\u662f\u53ef\u4ee5\u8fdb\u884c\u8bbe\u7f6e\u7684\uff1a<\/p>\n<pre><code class=\"language-python\">from fastapi import FastAPI\nimport uvicorn\n\napp = FastAPI(title=&quot;\u6d4b\u8bd5\u6587\u6863&quot;,\n              description=&quot;\u8fd9\u662f\u4e00\u4e2a\u7b80\u5355\u7684 demo&quot;,\n              docs_url=&quot;\/my_docs&quot;,\n              openapi_url=&quot;\/my_openapi&quot;)\n\n@app.get(&quot;\/items\/{item_id}&quot;)\nasync def get_item(item_id: int):\n    return {&quot;item_id&quot;: item_id}\n\nif __name__ == &quot;__main__&quot;:\n    uvicorn.run(&quot;main:app&quot;, host=&quot;0.0.0.0&quot;, port=5555)<\/code><\/pre>\n<p>\u7136\u540e\u6211\u4eec\u518d\u91cd\u65b0\u8fdb\u5165\uff0c\u6b64\u65f6\u5728\u6d4f\u89c8\u5668\u91cc\u5c31\u9700\u8981\u8f93\u5165 localhost:5555\/my_docs\uff1a<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/202211141537632.png\" alt=\"image-20221114153704177\" \/><\/p>\n<h2>4.\u4f7f\u7528\u679a\u4e3e<\/h2>\n<p>\u6211\u4eec\u53ef\u4ee5\u5c06\u67d0\u4e2a\u8def\u5f84\u53c2\u6570\u901a\u8fc7\u7c7b\u578b\u6ce8\u89e3\u7684\u65b9\u5f0f\u58f0\u660e\u4e3a\u6307\u5b9a\u7684\u7c7b\u578b\uff08\u51c6\u786e\u7684\u8bf4\u662f\u53ef\u4ee5\u8f6c\u6210\u6307\u5b9a\u7684\u7c7b\u578b\uff0c\u56e0\u4e3a\u9ed8\u8ba4\u90fd\u662f\u5b57\u7b26\u4e32\uff09\uff0c\u4f46\u5982\u679c\u6211\u4eec\u5e0c\u671b\u5b83\u53ea\u80fd\u662f\u89c4\u5b9a\u7684\u51e0\u4e2a\u503c\u4e4b\u4e00\uff0c\u8be5\u600e\u4e48\u505a\u5462\uff1f<\/p>\n<pre><code class=\"language-python\">from enum import Enum\nfrom fastapi import FastAPI\nimport uvicorn\n\napp = FastAPI()\n\nclass Name(str, Enum):\n    satori = &quot;\u53e4\u660e\u5730\u89c9&quot;\n    koishi = &quot;\u53e4\u660e\u5730\u604b&quot;\n    marisa = &quot;\u96fe\u96e8\u9b54\u7406\u6c99&quot;\n\n@app.get(&quot;\/users\/{user_name}&quot;)\nasync def get_user(user_name: Name):\n    return {&quot;user_id&quot;: user_name}\n\nif __name__ == &quot;__main__&quot;:\n    uvicorn.run(&quot;main:app&quot;, host=&quot;0.0.0.0&quot;, port=5555)<\/code><\/pre>\n<p>\u901a\u8fc7\u679a\u4e3e\u7684\u65b9\u5f0f\u53ef\u4ee5\u5b9e\u73b0\u8fd9\u4e00\u70b9\uff0c\u6211\u4eec\u6765\u6d4b\u8bd5\u4e00\u4e0b\uff1a<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/202211141605029.jpeg\" alt=\"\u56fe\u7247\" \/><\/p>\n<p>\u7ed3\u679c\u548c\u6211\u4eec\u671f\u671b\u7684\u662f\u4e00\u6837\u7684\uff0c\u53ef\u4ee5\u518d\u6765\u770b\u770b docs \u751f\u6210\u7684\u6587\u6863\uff1a<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/202211141605728.jpeg\" alt=\"\u56fe\u7247\" \/><\/p>\n<p>\u53ef\u7528\u7684\u503c\u90fd\u6709\u54ea\u4e9b\uff0c\u4e5f\u81ea\u52a8\u63d0\u793a\u7ed9\u6211\u4eec\u4e86\u3002<\/p>\n<h2>5. \u8def\u5f84\u5305\u542b \/<\/h2>\n<p>\u5047\u8bbe\u6211\u4eec\u6709\u8fd9\u6837\u4e00\u4e2a\u8def\u7531\uff1a<code>\/files\/{file_path}<\/code>\uff0c\u800c\u7528\u6237\u4f20\u9012\u7684 <code>file_path<\/code> \u4e2d\u663e\u7136\u662f\u53ef\u4ee5\u5e26 <code>\/<\/code> \u7684\u3002\u5047\u8bbe<code>file_path<\/code>\u662f<code>\/root\/test.py<\/code>\uff0c\u90a3\u4e48\u8def\u7531\u5c31\u53d8\u6210\u4e86 <code>\/files\/\/root\/test.py<\/code>\uff0c\u663e\u7136\u8fd9\u662f\u6709\u95ee\u9898\u7684\u3002<\/p>\n<pre><code class=\"language-python\">@app.get(&quot;\/users\/{user_name}&quot;)\nasync def get_user(user_name: Name):\n    return {&quot;user_id&quot;: user_name}<\/code><\/pre>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/202211151126597.png\" alt=\"image-20221115112355104\" \/><\/p>\n<p>\u90a3\u4e48\u4e3a\u4e86\u9632\u6b62\u89e3\u6790\u51fa\u9519\uff0c\u6211\u4eec\u9700\u8981\u505a\u4e00\u4e2a\u7c7b\u4f3c\u4e8e Flask \u7684\u64cd\u4f5c\uff1a<\/p>\n<pre><code class=\"language-python\">from fastapi import FastAPI\nimport uvicorn\n\napp = FastAPI()\n\n# \u58f0\u660e file_path \u7684\u7c7b\u578b\u4e3a path\n# \u8fd9\u6837\u5b83\u4f1a\u88ab\u5f53\u6210\u4e00\u4e2a\u6574\u4f53\n@app.get(&quot;\/files\/{file_path:path}&quot;)\nasync def get_file(file_path: str):\n    return {&quot;file_path&quot;: file_path}\n\nif __name__ == &quot;__main__&quot;:\n    uvicorn.run(&quot;main:app&quot;, host=&quot;0.0.0.0&quot;, port=5555)<\/code><\/pre>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/202211151930098.png\" alt=\"image-20221115112447781\" \/> <\/p>\n<p>\u7ed3\u679c\u6ca1\u6709\u95ee\u9898\uff0c\u5982\u679c\u4e0d\u5c06 file_path \u7684\u683c\u5f0f\u6307\u5b9a\u4e3a path\uff0c\u90a3\u4e48\u89e3\u6790\u7684\u65f6\u5019\u5c31\u4f1a\u627e\u4e0d\u5230\u6307\u5b9a\u7684\u8def\u7531\u3002<\/p>\n<h2>6.\u67e5\u8be2\u53c2\u6570<\/h2>\n<p>\u67e5\u8be2\u53c2\u6570\u5728 FastAPI \u4e2d\u4f9d\u65e7\u53ef\u4ee5\u901a\u8fc7\u7c7b\u578b\u6ce8\u89e3\u7684\u65b9\u5f0f\u8fdb\u884c\u58f0\u660e\uff0c\u5982\u679c\u51fd\u6570\u4e2d\u5b9a\u4e49\u4e86\u4e0d\u5c5e\u4e8e\u8def\u5f84\u53c2\u6570\u7684\u53c2\u6570\u65f6\uff0c\u5b83\u4eec\u5c06\u4f1a\u88ab\u89e3\u91ca\u4e3a\u67e5\u8be2\u53c2\u6570\u3002<\/p>\n<pre><code class=\"language-python\">from fastapi import FastAPI\nimport uvicorn\n\napp = FastAPI()\n\n@app.get(&quot;\/users\/{user_id}&quot;)\nasync def get_user(user_id: str, name: str, age: int):\n    &quot;&quot;&quot;\n    \u6211\u4eec\u5728\u51fd\u6570\u4e2d\u5b9a\u4e49\u4e86 user_id\u3001name\u3001age \u4e09\u4e2a\u53c2\u6570\n    \u663e\u7136 user_id \u548c \u8def\u5f84\u53c2\u6570\u4e2d\u7684 user_id \u5bf9\u5e94\n    \u7136\u540e name \u548c age \u4f1a\u88ab\u89e3\u91ca\u6210\u67e5\u8be2\u53c2\u6570\n    \u8fd9\u4e09\u4e2a\u53c2\u6570\u7684\u987a\u5e8f\u6ca1\u6709\u8981\u6c42\uff0c\u4f46\u4e00\u822c\u90fd\u662f\u8def\u5f84\u53c2\u6570\u5728\u524d\uff0c\u67e5\u8be2\u53c2\u6570\u5728\u540e\n    &quot;&quot;&quot;\n    return {&quot;user_id&quot;: user_id, &quot;name&quot;: name, &quot;age&quot;: age}\n\nif __name__ == &quot;__main__&quot;:\n    uvicorn.run(&quot;main:app&quot;, host=&quot;0.0.0.0&quot;, port=5555)<\/code><\/pre>\n<p>\u6ce8\u610f\uff1aname \u548c age \u6ca1\u6709\u9ed8\u8ba4\u503c\uff0c\u8fd9\u610f\u5473\u7740\u5b83\u4eec\u662f\u5fc5\u987b\u8981\u4f20\u9012\u7684\uff0c\u5426\u5219\u62a5\u9519\u3002<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/202211151129906.png\" alt=\"image-20221115112940769\" \/><\/p>\n<p>\u4f20\u5165\u53c2\u6570\u540e\uff1a<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/202211151130851.png\" alt=\"image-20221115113024175\" \/><\/p>\n<p>\u6211\u4eec\u770b\u5230\u5f53\u4e0d\u4f20\u9012 name \u548c age \u7684\u65f6\u5019\uff0c\u4f1a\u76f4\u63a5\u63d0\u793a\u4f60\u76f8\u5173\u7684\u9519\u8bef\u4fe1\u606f\u3002\u5982\u679c\u6211\u4eec\u5e0c\u671b\u7528\u6237\u53ef\u4ee5\u4e0d\u4f20\u9012\u7684\u8bdd\uff0c\u90a3\u4e48\u5fc5\u987b\u8981\u6307\u5b9a\u4e00\u4e2a\u9ed8\u8ba4\u503c\u3002<\/p>\n<pre><code class=\"language-python\">@app.get(&quot;\/users\/{user_id}&quot;)\nasync def get_user(user_id: str, name: str = &quot;UNKNOWN&quot;, age: int = 0):\n    &quot;&quot;&quot;\n    \u6211\u4eec\u5728\u51fd\u6570\u4e2d\u5b9a\u4e49\u4e86 user_id\u3001name\u3001age \u4e09\u4e2a\u53c2\u6570\n    \u663e\u7136 user_id \u548c \u8def\u5f84\u53c2\u6570\u4e2d\u7684 user_id \u5bf9\u5e94\n    \u7136\u540e name \u548c age \u4f1a\u88ab\u89e3\u91ca\u6210\u67e5\u8be2\u53c2\u6570\n    \u8fd9\u4e09\u4e2a\u53c2\u6570\u7684\u987a\u5e8f\u6ca1\u6709\u8981\u6c42\uff0c\u4f46\u4e00\u822c\u90fd\u662f\u8def\u5f84\u53c2\u6570\u5728\u524d\uff0c\u67e5\u8be2\u53c2\u6570\u5728\u540e\n    &quot;&quot;&quot;\n    return {&quot;user_id&quot;: user_id, &quot;name&quot;: name, &quot;age&quot;: age}<\/code><\/pre>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/202211151934597.png\" alt=\"image-20221115113207940\" \/> <\/p>\n<p>\u6211\u4eec\u770b\u5230\uff0c\u4f20\u9012\u7684 age \u4f9d\u65e7\u9700\u8981\u6574\u578b\uff0c\u53ea\u4e0d\u8fc7\u5728\u4e0d\u4f20\u7684\u65f6\u5019\u4f1a\u4f7f\u7528\u5b57\u7b26\u4e32\u7c7b\u578b\u7684\u9ed8\u8ba4\u503c\u3002\u6240\u4ee5\u6307\u5b9a\u7684\u7c7b\u578b\u548c\u9ed8\u8ba4\u503c\u7c7b\u578b\u4e0d\u76f8\u540c\uff0c\u4e5f\u662f\u5141\u8bb8\u7684\uff0c\u53ea\u4e0d\u8fc7\u8fd9\u4e48\u505a\u663e\u7136\u662f\u4e0d\u5408\u7406\u7684\u3002<\/p>\n<p>\u6b64\u5916\u6211\u4eec\u8fd8\u53ef\u4ee5\u6307\u5b9a\u591a\u4e2a\u7c7b\u578b\uff0c\u6bd4\u5982\u8ba9 user_id \u6309\u7167\u6574\u578b\u89e3\u6790\u3001\u89e3\u6790\u4e0d\u6210\u529f\u65f6\u9000\u5316\u4e3a\u5b57\u7b26\u4e32\u3002<\/p>\n<pre><code class=\"language-python\">from typing import Union, Optional\nfrom fastapi import FastAPI\nimport uvicorn\n\napp = FastAPI()\n\n@app.get(&quot;\/users\/{user_id}&quot;)\nasync def get_user(user_id: Union[int, str],\n                   name: Optional[str] = None):\n    &quot;&quot;&quot;\n    \u901a\u8fc7 Union \u6765\u58f0\u660e\u4e00\u4e2a\u6df7\u5408\u7c7b\u578b\uff0cint \u5728\u524d\u3001str \u5728\u540e\n    \u4f1a\u5148\u6309\u7167 int \u89e3\u6790\uff0c\u89e3\u6790\u5931\u8d25\u518d\u53d8\u6210 str\n    \u7136\u540e\u662f name\uff0c\u5b83\u8868\u793a\u5b57\u7b26\u4e32\u7c7b\u578b\u3001\u4f46\u9ed8\u8ba4\u503c\u4e3a None\uff08\u4e0d\u662f\u5b57\u7b26\u4e32\uff09\n    \u90a3\u4e48\u5e94\u8be5\u58f0\u660e\u4e3a Optional[str]\n    &quot;&quot;&quot;\n    return {&quot;user_id&quot;: user_id, &quot;name&quot;: name}\n\nif __name__ == &quot;__main__&quot;:\n    uvicorn.run(&quot;main:app&quot;, host=&quot;0.0.0.0&quot;, port=5555)<\/code><\/pre>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/202211151139809.png\" alt=\"image-20221115113900712\" \/><\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/202211151139122.png\" alt=\"image-20221115113922748\" \/><\/p>\n<p>\u6240\u4ee5 FastAPI \u7684\u8bbe\u8ba1\u8fd8\u662f\u975e\u5e38\u4e0d\u9519\u7684\uff0c\u901a\u8fc7 Python \u7684\u7c7b\u578b\u6ce8\u89e3\u6765\u5b9e\u73b0\u53c2\u6570\u7c7b\u578b\u7684\u9650\u5b9a\u53ef\u4ee5\u8bf4\u662f\u975e\u5e38\u5de7\u5999\u7684\uff0c\u56e0\u6b64\u8fd9\u4e5f\u9700\u8981\u6211\u4eec\u719f\u7ec3\u638c\u63e1 Python \u7684\u7c7b\u578b\u6ce8\u89e3\u3002<\/p>\n<p>\u8fd9\u91cc\u8865\u5145\u4e00\u4e0b\uff0c\u6211\u5f53\u524d\u7684 Python \u7248\u672c\u662f 3.8\uff0c\u5982\u679c\u4f60\u7528\u7684\u662f 3.10\uff0c\u90a3\u4e48\u7c7b\u578b\u6ce8\u89e3\u8fd8\u6709\u4e0d\u540c\u7684\u5199\u6cd5\uff1a<\/p>\n<pre><code class=\"language-shell\">>&gt;&gt; from typing import Union, Optional\n# Optional[str] \u548c str | None \u7b49\u4ef7\n>&gt;&gt; name: Optional[str] = &quot;\u53e4\u660e\u5730\u89c9&quot;\n>&gt;&gt; name: str | None = &quot;\u53e4\u660e\u5730\u89c9&quot;\n# Union[int, str] \u548c int | str \u7b49\u4ef7\n>&gt;&gt; age: Union[int, str] = 17\n>&gt;&gt; age: int | str = 17<\/code><\/pre>\n<p>\u8fd9\u79cd\u5199\u6cd5\u5728 3.10 \u624d\u5f00\u59cb\u6b63\u5f0f\u5f15\u5165\uff0c\u4f46\u901a\u8fc7 <code>from __future__ import annotations<\/code> \u4e5f\u53ef\u4ee5\u5728 3.9 \u91cc\u9762\u4f7f\u7528\uff0c\u800c 3.8 \u662f\u4e0d\u652f\u6301\u7684\u3002<\/p>\n<h3>6.1\u5e03\u5c14\u7c7b\u578b\u81ea\u52a8\u8f6c\u6362<\/h3>\n<p>\u5bf9\u4e8e\u5e03\u5c14\u7c7b\u578b\uff0cFastAPI \u652f\u6301\u81ea\u52a8\u8f6c\u6362\uff0c\u4e3e\u4e2a\u4f8b\u5b50\uff1a<\/p>\n<pre><code class=\"language-python\">@app.get(&quot;\/{flag}&quot;)\nasync def get_flag(flag: bool):\n    return {&quot;flag&quot;: flag}<\/code><\/pre>\n<p>0\/false\/off\/yes --- &gt; {'flag': True}<\/p>\n<p>1\/true\/on\/no  --- &gt; {'flag': False}<\/p>\n<h3>6.2\u591a\u4e2a\u8def\u5f84\u548c\u67e5\u8be2\u53c2\u6570<\/h3>\n<p>\u524d\u9762\u8bf4\u8fc7\uff0c\u53ef\u4ee5\u5b9a\u4e49\u4efb\u610f\u4e2a\u8def\u5f84\u53c2\u6570\uff0c\u53ea\u8981\u52a8\u6001\u7684\u8def\u5f84\u53c2\u6570 {} \u5728\u51fd\u6570\u7684\u53c2\u6570\u4e2d\u90fd\u51fa\u73b0\u5373\u53ef\u3002\u5f53\u7136\u67e5\u8be2\u53c2\u6570\u4e5f\u53ef\u4ee5\u662f\u4efb\u610f\u4e2a\uff0cFastAPI \u53ef\u4ee5\u5904\u7406\u7684\u5f88\u597d\u3002<\/p>\n<pre><code class=\"language-python\">from typing import Union, Optional\nfrom fastapi import FastAPI\nimport uvicorn\n\napp = FastAPI()\n\n@app.get(&quot;\/postgres\/{schema}\/v1\/{table}&quot;)\nasync def get_data(schema: str,\n                   table: str,\n                   select: str = &quot;*&quot;,\n                   where: Optional[str] = None,\n                   limit: Optional[int] = None,\n                   offset: Optional[int] = None):\n    &quot;&quot;&quot;\n    \u6807\u51c6\u683c\u5f0f\u662f\uff1a\u8def\u5f84\u53c2\u6570\u6309\u7167\u987a\u5e8f\u5728\u524d\uff0c\u67e5\u8be2\u53c2\u6570\u5728\u540e\n    \u4f46 FastAPI \u5bf9\u987a\u5e8f\u672c\u8eab\u662f\u6ca1\u6709\u4ec0\u4e48\u8981\u6c42\u7684\n    &quot;&quot;&quot;\n    query = f&quot;select {select} from {schema}.{table}&quot;\n    print(query)\n    if where:\n        query += f&quot; where {where}&quot;\n    if limit:\n        query += f&quot; limit {limit}&quot;\n    if offset:\n        query += f&quot; offset {offset}&quot;\n    return {&quot;query&quot;: query}\n\nif __name__ == &quot;__main__&quot;:\nfrom typing import Union, Optional\nfrom fastapi import FastAPI\nimport uvicorn\n\napp = FastAPI()\n\n@app.get(&quot;\/postgres\/{schema}\/v1\/{table}&quot;)\nasync def get_data(schema: str,\n                   table: str,\n                   select: str = &quot;*&quot;,\n                   where: Optional[str] = None,\n                   limit: Optional[int] = None,\n                   offset: Optional[int] = None):\n    &quot;&quot;&quot;\n    \u6807\u51c6\u683c\u5f0f\u662f\uff1a\u8def\u5f84\u53c2\u6570\u6309\u7167\u987a\u5e8f\u5728\u524d\uff0c\u67e5\u8be2\u53c2\u6570\u5728\u540e\n    \u4f46 FastAPI \u5bf9\u987a\u5e8f\u672c\u8eab\u662f\u6ca1\u6709\u4ec0\u4e48\u8981\u6c42\u7684\n    &quot;&quot;&quot;\n    query = f&quot;select {select} from {schema}.{table}&quot;\n    print(query)\n    if where:\n        query += f&quot; where {where}&quot;\n    if limit:\n        query += f&quot; limit {limit}&quot;\n    if offset:\n        query += f&quot; offset {offset}&quot;\n    return {&quot;query&quot;: query}\n\nif __name__ == &quot;__main__&quot;:\n    uvicorn.run(&quot;main:app&quot;, host=&quot;0.0.0.0&quot;, port=5555, reload=True)<\/code><\/pre>\n<h3>6.3 \u4f9d\u8d56\u6ce8\u5165Depends<\/h3>\n<pre><code class=\"language-python\">from typing import Optional\nfrom fastapi import FastAPI, Depends\nimport uvicorn\n\napp = FastAPI()\n\nasync def common_parameters(\n        select: str = &quot;*&quot;,\n        skip: int = 0,\n        limit: int = 100\n):\n    return {&quot;select&quot;: select, &quot;skip&quot;: skip, &quot;limit&quot;: limit}\n\n@app.get(&quot;\/items&quot;)\nasync def read_items(\n        commons: dict = Depends(common_parameters)):\n    &quot;&quot;&quot;\n    common_parameters \u63a5\u6536\u4e09\u4e2a\u53c2\u6570\uff1aq\u3001skip\u3001limit\n    \u56e0\u6b64\u4f1a\u4ece\u8bf7\u6c42\u4e2d\u89e3\u6790\u51fa q\u3001skip\u3001limit \u5e76\u4f20\u7ed9 common_parameters\n    \u7136\u540e\u5c06 common_parameters \u7684\u8fd4\u56de\u503c\u8d4b\u7ed9 commons\n    \u4f46\u5982\u679c\u89e3\u6790\u4e0d\u5230\u67d0\u4e2a\u53c2\u6570\uff0c\u90a3\u4e48\u4f1a\u5224\u65ad\u51fd\u6570\u4e2d\u53c2\u6570\u662f\u5426\u6709\u9ed8\u8ba4\u503c\n    \u6ca1\u6709\u7684\u8bdd\u5c31\u4f1a\u8fd4\u56de\u9519\u8bef\n    &quot;&quot;&quot;\n    return commons\n\nif __name__ == &quot;__main__&quot;:\n    uvicorn.run(&quot;main:app&quot;, host=&quot;0.0.0.0&quot;, port=5555, reload=True)<\/code><\/pre>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/202211151410831.png\" alt=\"image-20221115141031798\" \/> <\/p>\n<hr \/>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/202211151412749.png\" alt=\"image-20221115141240832\" \/> <\/p>\n<h2>7.\u6570\u636e\u6821\u9a8c(\u9488\u5bf9\u67e5\u8be2\u53c2\u6570)<\/h2>\n<h3>7.1 fastapi.Query<\/h3>\n<p>FastAPI \u652f\u6301\u6211\u4eec\u8fdb\u884c\u66f4\u52a0\u667a\u80fd\u7684\u6570\u636e\u6821\u9a8c\uff0c\u6bd4\u5982\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u6211\u4eec\u5e0c\u671b\u7528\u6237\u5728\u4f20\u9012\u7684\u65f6\u5019\u53ea\u80fd\u4f20\u9012\u957f\u5ea6\u4e3a 6 \u5230 15 \u7684\u5b57\u7b26\u4e32\u8be5\u600e\u4e48\u505a\u5462\uff1f<\/p>\n<p><code>from fastapi import Query<\/code><\/p>\n<pre><code class=\"language-python\">from typing import Optional\nfrom fastapi import FastAPI, Query\nimport uvicorn\n\napp = FastAPI()\n\n@app.get(&quot;\/user&quot;)\nasync def check_length(\n        password: Optional[str] = Query(None, min_length=6, max_length=15)\n        ):\n    &quot;&quot;&quot;\n    \u9ed8\u8ba4\u503c\u4e3a None\uff0c\u5e94\u8be5\u58f0\u660e\u4e3a Optional[str]\uff0c\u5f53\u7136\u58f0\u660e str \u4e5f\u662f\u53ef\u4ee5\u7684\n    \u53ea\u4e0d\u8fc7\u58f0\u660e\u4e3a str\uff0c\u90a3\u4e48\u9ed8\u8ba4\u503c\u5e94\u8be5\u4e5f\u662f str\n    \u6240\u4ee5\u5982\u679c\u5141\u8bb8\u4e00\u4e2a\u7c7b\u578b\u7684\u503c\u4e3a\u7a7a\uff0c\u90a3\u4e48\u66f4\u89c4\u8303\u7684\u505a\u6cd5\u5e94\u8be5\u662f\u58f0\u660e\u4e3a Optional[\u7c7b\u578b]\n    &quot;&quot;&quot;\n\n    return {&quot;password&quot;: password}\n\nif __name__ == &quot;__main__&quot;:\n    uvicorn.run(&quot;main:app&quot;, host=&quot;0.0.0.0&quot;, port=5555, reload=True)<\/code><\/pre>\n<p>password \u662f\u53ef\u9009\u7684\uff0c\u4f46\u4f20\u9012\u7684\u65f6\u5019\u5fc5\u987b\u4f20\u5b57\u7b26\u4e32\u3001\u800c\u4e14\u8fd8\u662f\u957f\u5ea6\u5728 6 \u5230 15 \u4e4b\u95f4\u7684\u5b57\u7b26\u4e32\u3002\u6240\u4ee5\u5728\u58f0\u660e\u9ed8\u8ba4\u503c\u7684\u65f6\u5019 None \u548c Query(None) \u662f\u7b49\u4ef7\u7684\uff0c\u53ea\u4e0d\u8fc7 Query \u8fd8\u652f\u6301\u5bf9\u53c2\u6570\u8fdb\u884c\u989d\u5916\u7684\u9650\u5236\u3002<\/p>\n<p>\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/202211151702289.png\" alt=\"image-20221115170250230\" \/> <\/p>\n<p>Query \u91cc\u9762\u9664\u4e86\u9650\u5236\u6700\u5c0f\u957f\u5ea6\u548c\u6700\u5927\u957f\u5ea6\uff0c\u8fd8\u6709\u5176\u5b83\u7684\u529f\u80fd\uff1a<\/p>\n<pre><code class=\"language-python\">from fastapi import FastAPI, Query\nq = Query(None, min_length=6, max_length=15)<\/code><\/pre>\n<p>\u6211\u4eec\u67e5\u770bq\u7684\u5c5e\u6027\uff1a<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/202211151701620.png\" alt=\"image-20221115170114245\" \/> <\/p>\n<p>\u66f4\u6539\u70b9\u4ee3\u7801\uff1a<\/p>\n<pre><code class=\"language-python\">@app.get(&quot;\/user&quot;)\nasync def check_length(\n    password: str = Query(&quot;satori&quot;, min_length=6, \n                          max_length=15, regex=r&quot;^satori&quot;)\n):\n    &quot;&quot;&quot;\n    \u6b64\u65f6 password \u7684\u9ed8\u8ba4\u503c\u4e3a &#039;satori&#039;\uff0c\u5e76\u4e14\u4f20\u9012\u7684\u65f6\u5019\u4e5f\u5fc5\u987b\u8981\u4ee5 &#039;satori&#039; \u5f00\u5934\n    \u4f46\u503c\u5f97\u6ce8\u610f\u7684\u662f password \u540e\u9762\u7684\u7c7b\u578b\u6ce8\u89e3\u662f str\uff0c\u4e0d\u518d\u662f Optional[str]\n    \u56e0\u4e3a\u9ed8\u8ba4\u503c\u4e0d\u662f None \u4e86\uff0c\u5f53\u7136\u8fd9\u91cc\u5373\u4f7f\u5199\u6210 Optional[str] \u4e5f\u662f\u6ca1\u6709\u4ec0\u4e48\u5f71\u54cd\u7684\n    &quot;&quot;&quot;\n    return {&quot;password&quot;: password}<\/code><\/pre>\n<hr \/>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/202211151710514.png\" alt=\"image-20221115171035906\" \/> <\/p>\n<hr \/>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/202211151710943.png\" alt=\"image-20221115171056947\" \/> <\/p>\n<hr \/>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/202211151709493.png\" alt=\"image-20221115170857887\" \/> <\/p>\n<hr \/>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/202211151708999.png\" alt=\"image-20221115170816721\" \/> <\/p>\n<hr \/>\n<h3>7.2 \u58f0\u660e\u67e5\u8be2\u53c2\u6570\u4e3a\u5fc5\u4f20\u53c2\u6570<\/h3>\n<p>\u5982\u679c\u6211\u4eec\u60f3\u8ba9\u67d0\u4e2a\u67e5\u8be2\u53c2\u6570\u4e3a\u5fc5\u4f20\u53c2\u6570\uff0c\u53ea\u9700\u8981\u4e0d\u7ed9\u5b83\u9ed8\u8ba4\u503c\u5c31\u884c\u4e86\u3002<\/p>\n<p>\u51fd\u6570\u91cc\u9762\u7684\u53c2\u6570\uff0c\u8981\u4e48\u662f\u8def\u5f84\u53c2\u6570\u3001\u8981\u4e48\u662f\u67e5\u8be2\u53c2\u6570\u3002\u663e\u7136 password \u662f\u4e00\u4e2a\u67e5\u8be2\u53c2\u6570\uff0c\u901a\u8fc7\u4e0d\u6307\u5b9a\u9ed8\u8ba4\u503c\uff0c\u6211\u4eec\u5373\u53ef\u5b9e\u73b0\u5b83\u662f\u4e00\u4e2a\u5fc5\u4f20\u53c2\u6570\u3002\u4e5f\u5c31\u662f\u5728 URL \u4e2d\uff0c\u5fc5\u987b\u901a\u8fc7 ?password=xxx \u7684\u65b9\u5f0f\u8fdb\u884c\u4f20\u9012\u3002<\/p>\n<p>\u867d\u7136\u76ee\u7684\u5f88\u7b80\u5355\uff0c\u4f46\u6211\u4eec\u53d1\u73b0\u6b64\u65f6\u65e0\u6cd5\u5bf9 password \u8fdb\u884c\u9650\u5236\u4e86\uff0c\u6bd4\u5982\u5e0c\u671b\u5b83\u7684\u957f\u5ea6\u662f 6 \u5230 15\u3002\u90a3\u4e48\u95ee\u9898\u6765\u4e86\uff0c\u5982\u4f55\u624d\u80fd\u4e24\u8005\u517c\u987e\u5462\uff1f<\/p>\n<pre><code class=\"language-python\">from typing import Optional\nfrom fastapi import FastAPI, Query\nimport uvicorn\n\napp = FastAPI()\n\n@app.get(&quot;\/user&quot;)\nasync def check_length(\n        password: Optional[str] = Query(..., min_length=6, max_length=15)):\n    &quot;&quot;&quot;\n    \u9ed8\u8ba4\u503c\u4e3a None\uff0c\u5e94\u8be5\u58f0\u660e\u4e3a Optional[str]\uff0c\u5f53\u7136\u58f0\u660e str \u4e5f\u662f\u53ef\u4ee5\u7684\n    \u53ea\u4e0d\u8fc7\u58f0\u660e\u4e3a str\uff0c\u90a3\u4e48\u9ed8\u8ba4\u503c\u5e94\u8be5\u4e5f\u662f str\n    \u6240\u4ee5\u5982\u679c\u5141\u8bb8\u4e00\u4e2a\u7c7b\u578b\u7684\u503c\u4e3a\u7a7a\uff0c\u90a3\u4e48\u66f4\u89c4\u8303\u7684\u505a\u6cd5\u5e94\u8be5\u662f\u58f0\u660e\u4e3a Optional[\u7c7b\u578b]\n    -----------------------------------------------------------------\n    \u6b64\u65f6 password \u7684\u9ed8\u8ba4\u503c\u4e3a &#039;satori&#039;\uff0c\u5e76\u4e14\u4f20\u9012\u7684\u65f6\u5019\u4e5f\u5fc5\u987b\u8981\u4ee5 &#039;satori&#039; \u5f00\u5934\n    \u4f46\u503c\u5f97\u6ce8\u610f\u7684\u662f password \u540e\u9762\u7684\u7c7b\u578b\u6ce8\u89e3\u662f str\uff0c\u4e0d\u518d\u662f Optional[str]\n    \u56e0\u4e3a\u9ed8\u8ba4\u503c\u4e0d\u662f None \u4e86\uff0c\u5f53\u7136\u8fd9\u91cc\u5373\u4f7f\u5199\u6210 Optional[str] \u4e5f\u662f\u6ca1\u6709\u4ec0\u4e48\u5f71\u54cd\u7684\n    &quot;&quot;&quot;\n\n    return {&quot;password&quot;: password}\n\nif __name__ == &quot;__main__&quot;:\n    uvicorn.run(&quot;main:app&quot;, host=&quot;0.0.0.0&quot;, port=5555, reload=True)<\/code><\/pre>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/202211151907375.png\" alt=\"image-20221115190736037\" \/> <\/p>\n<hr \/>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/202211151906677.png\" alt=\"image-20221115190633816\" \/> <\/p>\n<p>... \u662f Python \u7684\u4e00\u4e2a\u7279\u6b8a\u7684\u5bf9\u8c61\uff0c\u53ef\u4ee5\u4e86\u89e3\u4e00\u4e0b\uff0c\u5728 Numpy \u91cc\u9762\u4e5f\u53ef\u4ee5\u4f7f\u7528\u5b83\u3002<\/p>\n<p>\u6700\u540e\u518d\u8865\u5145\u4e00\u70b9\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u4e0d\u4f7f\u7528 Query\uff0c\u5c06 password \u7684\u957f\u5ea6\u9650\u5236\u903b\u8f91\u5199\u5728\u51fd\u6570\u4f53\u91cc\u9762\u4e5f\u662f\u4e00\u6837\u7684\u3002<\/p>\n<h3>7.3 \u540c\u65f6\u83b7\u53d6\u591a\u4e2a\u76f8\u540c\u7684\u67e5\u8be2\u53c2\u6570<\/h3>\n<p>\u5982\u679c\u6211\u4eec\u6307\u5b9a\u4e86 a=1&amp;a=2\uff0c\u90a3\u4e48\u5728\u83b7\u53d6 a \u7684\u65f6\u5019\uff0c\u4f1a\u5f97\u5230\u4ec0\u4e48\u5462\uff1f<\/p>\n<pre><code class=\"language-python\">from typing import List\nfrom fastapi import FastAPI, Query\nimport uvicorn\n\napp = FastAPI()\n\n@app.get(&quot;\/items&quot;)\nasync def read_items(\n        a1: str = Query(...),\n        a2: List[str] = Query(...),\n        b: List[str] = Query(...)\n):\n    return {&quot;a1&quot;: a1, &quot;a2&quot;: a2, &quot;b&quot;: b}<\/code><\/pre>\n<p>\u6211\u4eec\u8bbf\u95ee\u4e00\u4e0b\uff0c\u770b\u770b\u7ed3\u679c\uff1a<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/202211151911912.png\" alt=\"image-20221115191138426\" \/> <\/p>\n<hr \/>\n<p>\u9996\u5148 a2 \u548c b \u90fd\u662f\u5217\u8868\uff0c\u4f1a\u83b7\u53d6\u6240\u6709\u7684\u503c\uff0c\u4f46 a1 \u53ea\u83b7\u53d6\u4e86\u6700\u540e\u4e00\u4e2a\u503c\u3002<\/p>\n<p>\u53e6\u5916\u53ef\u80fd\u6709\u4eba\u89c9\u5f97\u4ee3\u7801\u6709\u70b9\u5570\u55e6\uff0c\u5728\u51fd\u6570\u58f0\u660e\u4e2d\u53ef\u4e0d\u53ef\u4ee5\u8fd9\u6837\u5199\u5462\uff1f<\/p>\n<pre><code class=\"language-python\">@app.get(&quot;\/items&quot;)\nasync def read_items(\n        a1: str,\n        a2: List[str],\n        b: List[str]\n):\n    return {&quot;a1&quot;: a1, &quot;a2&quot;: a2, &quot;b&quot;: b}<\/code><\/pre>\n<p>\u6211\u4eec\u5c06 Query(...) \u53bb\u6389\u4e86\uff0c\u56e0\u4e3a\u5b83\u6ca1\u6709\u5bf9\u53c2\u6570\u505a\u5176\u5b83\u7684\u9650\u5236\uff0c\u53ea\u662f\u8868\u793a\u53c2\u6570\u662f\u4e00\u4e2a\u5fc5\u4f20\u53c2\u6570\u3002\u800c\u4e0d\u6307\u5b9a Query(...)\uff0c\u90a3\u4e48\u672c\u8eab\u5c31\u662f\u4e00\u4e2a\u5fc5\u4f20\u53c2\u6570\uff0c\u6240\u4ee5\u5b8c\u5168\u53ef\u4ee5\u628a Query(...) \u53bb\u6389\u3002<\/p>\n<p>\u8fd9\u79cd\u505a\u6cd5\uff0c\u5bf9\u4e8e a1 \u6765\u8bf4\u662f\u53ef\u884c\u7684\uff0c\u4f46\u5bf9\u4e8e a2 \u548c b \u6765\u8bf4\u4e0d\u884c\u3002\u5bf9\u4e8e\u7c7b\u578b\u4e3a list \u7684\u67e5\u8be2\u53c2\u6570\uff0c\u6211\u4eec\u5fc5\u987b\u8981\u663e\u5f0f\u7684\u52a0\u4e0a Query(...) \u6765\u8868\u793a\u5fc5\u4f20\u53c2\u6570\u3002\u5982\u679c\u5141\u8bb8\u4e3a None\uff08\u6216\u8005\u6709\u9ed8\u8ba4\u503c\uff09\u7684\u8bdd\uff0c\u90a3\u4e48\u5e94\u8be5\u8fd9\u4e48\u5199\uff1a<\/p>\n<pre><code class=\"language-python\">@app.get(&quot;\/items&quot;)\nasync def read_items(\n    a1: str,\n    a2: Optional[List[str]] = Query(None),\n    b: List[str] = Query([&quot;1&quot;, &quot;\u563f\u563f&quot;])\n):\n    return {&quot;a1&quot;: a1, &quot;a2&quot;: a2, &quot;b&quot;: b}<\/code><\/pre>\n<hr \/>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/202211151913820.png\" alt=\"image-20221115191352054\" \/> <\/p>\n<hr \/>\n<h3>7.4 \u7ed9\u53c2\u6570\u8d77\u522b\u540d<\/h3>\n<p>\u95ee\u9898\u6765\u4e86\uff0c\u5047\u8bbe\u6211\u4eec\u5b9a\u4e49\u7684\u67e5\u8be2\u53c2\u6570\u540d\u53eb item-query\uff0c\u90a3\u4e48\u7531\u4e8e\u5b83\u8981\u4f53\u73b0\u5728\u51fd\u6570\u53c2\u6570\u4e2d\uff0c\u800c\u8fd9\u663e\u7136\u4e0d\u7b26\u5408 Python \u53d8\u91cf\u7684\u547d\u540d\u89c4\u8303\uff0c\u8fd9\u4e2a\u65f6\u5019\u8981\u600e\u4e48\u505a\u5462\uff1f<\/p>\n<p><code>Query(alias=&quot;***&quot;)<\/code><\/p>\n<pre><code class=\"language-python\">@app.get(&quot;\/items&quot;)\nasync def read_items(\n    # \u4e09\u4e2a\u67e5\u8be2\u53c2\u6570\uff0c\u5206\u522b\u662f item-query\u3001@@@@\u3001$$$$\n    # \u4f46\u5b83\u4eec\u4e0d\u7b26\u5408 Python \u53d8\u91cf\u7684\u547d\u540d\u89c4\u8303\n    # \u4e8e\u662f\u8981\u4e3a\u5b83\u4eec\u8d77\u522b\u540d\n    item1: Optional[str] = Query(None, alias=&quot;item-query&quot;),\n    item2: str = Query(&quot;\u54c8\u54c8&quot;, alias=&quot;@@@@&quot;),\n    # item3 \u662f\u5fc5\u4f20\u7684\n    item3: str = Query(..., alias=&quot;$$$$&quot;)  \n):\n    return {&quot;item-query&quot;: item1, &quot;@@@@&quot;: item2, &quot;$$$$&quot;: item3}<\/code><\/pre>\n<hr \/>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/202211151918505.png\" alt=\"image-20221115191854373\" \/><\/p>\n<hr \/>\n<h3>7.5 \u6570\u636e\u68c0\u6d4b<\/h3>\n<p>Query \u4e0d\u4ec5\u4ec5\u652f\u6301\u5bf9\u5b57\u7b26\u4e32\u7684\u6821\u9a8c\uff0c\u8fd8\u652f\u6301\u5bf9\u6570\u503c\u7684\u6821\u9a8c\uff0c\u91cc\u9762\u53ef\u4ee5\u4f20\u9012<code> gt, ge, lt, le <\/code>\u7b49\u53c2\u6570\uff0c\u76f8\u4fe1\u8fd9\u51e0\u4e2a\u53c2\u6570\u4e0d\u7528\u8bf4\u4f60\u4e5f\u77e5\u9053\u662f\u5e72\u4ec0\u4e48\u7684\uff0c\u6211\u4eec\u4e3e\u4f8b\u8bf4\u660e\uff1a<\/p>\n<pre><code class=\"language-python\">@app.get(&quot;\/items&quot;)\nasync def read_items(\n    # item1 \u5fc5\u987b\u5927\u4e8e 5\n    item1: int = Query(..., gt=5),\n    # item2 \u5fc5\u987b\u5c0f\u4e8e\u7b49\u4e8e 7\n    item2: int = Query(..., le=7),\n\n    # item3 \u5fc5\u987b\u7b49\u4e8e 10\n    item3: int = Query(..., ge=10, le=10)\n):\n    return {&quot;item1&quot;: item1, \n            &quot;item2&quot;: item2, \n            &quot;item3&quot;: item3}<\/code><\/pre>\n<ul>\n<li>gt\uff1a\u8868\u793a\u5927\u4e8e&gt;\u3002\u5373greater than<\/li>\n<li>ge\uff1a\u8868\u793a\u5927\u4e8e\u7b49\u4e8e&gt;=\u3002\u5373greater than or equals to<\/li>\n<li>lt\uff1a\u8868\u793a\u5c0f\u4e8e&lt;\u3002\u5373less than<\/li>\n<li>le\uff1a\u8868\u793a\u5c0f\u4e8e\u7b49\u4e8e&lt;=\u3002\u5373less than or equals to<\/li>\n<li>eq\uff1a\u8868\u793a\u7b49\u4e8e=\u3002\u5373equals<\/li>\n<li>ne\uff1a\u8868\u793a\u4e0d\u7b49\u4e8e!=\u3002\u5373not equals<\/li>\n<\/ul>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/202211151930382.png\" alt=\"image-20221115192330789\" \/> <\/p>\n<hr \/>\n<p>\u4e0d\u7b26\u5408\u6761\u4ef6\u7684\u53c2\u6570\u5219\u4f1a\u62a5\u9519\uff1a<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/202211151924438.png\" alt=\"image-20221115192402454\" \/> <\/p>\n<hr \/>\n<p>Query \u8fd8\u662f\u6bd4\u8f83\u5f3a\u5927\u7684 \uff0c\u5f53\u7136\u5185\u90e8\u8fd8\u6709\u4e00\u4e9b\u5176\u5b83\u7684\u53c2\u6570\u662f\u9488\u5bf9 docs \u4ea4\u4e92\u6587\u6863\u7684\uff0c\u6709\u5174\u8da3\u53ef\u4ee5\u81ea\u5df1\u4e86\u89e3\u4e00\u4e0b\u3002<\/p>\n<h2>8.\u6570\u636e\u6821\u9a8c\uff08\u9488\u5bf9\u8def\u5f84\u53c2\u6570\uff09<\/h2>\n<p>\u5bf9\u67e5\u8be2\u53c2\u6570\u8fdb\u884c\u6570\u636e\u6821\u9a8c\u4f7f\u7528\u7684\u662f Query\uff0c\u5bf9\u8def\u5f84\u53c2\u6570\u8fdb\u884c\u6570\u636e\u6821\u9a8c\u4f7f\u7528\u7684\u662f Path\uff0c\u4e24\u8005\u7684\u4f7f\u7528\u65b9\u5f0f\u4e00\u6a21\u4e00\u6837\uff0c\u6ca1\u6709\u4efb\u4f55\u533a\u522b\u3002<\/p>\n<pre><code class=\"language-python\">from fastapi import FastAPI, Path\nimport uvicorn\n\napp = FastAPI()\n\n@app.get(&quot;\/items\/{item-id}&quot;)\nasync def read_items(\n    item_id: int = Path(..., alias=&quot;item-id&quot;)\n):\n    return {&quot;item-id&quot;: item_id}<\/code><\/pre>\n<p>\u8def\u5f84\u53c2\u6570\u662f\u5fc5\u987b\u7684\uff0c\u5b83\u662f\u8def\u5f84\u7684\u4e00\u90e8\u5206\uff0c\u6240\u4ee5\u6211\u4eec\u5e94\u8be5\u4f7f\u7528 <code>...<\/code> \u5c06\u5176\u6807\u8bb0\u4e3a\u5fc5\u4f20\u53c2\u6570\u3002\u5f53\u7136\u5373\u4f7f\u4e0d\u6807\u8bb0\u4e5f\u65e0\u6240\u8c13\uff0c\u5c31\u7b97\u6307\u5b9a\u4e86\u9ed8\u8ba4\u503c\u4e5f\u7528\u4e0d\u4e0a\uff0c\u56e0\u4e3a\u8def\u5f84\u53c2\u6570\u4e0d\u6307\u5b9a\u538b\u6839\u5c31\u5339\u914d\u4e0d\u5230\u76f8\u5e94\u7684\u8def\u7531\u3002\u81f3\u4e8e\u4e00\u4e9b\u5176\u5b83\u7684\u6821\u9a8c\uff0c\u548c\u67e5\u8be2\u53c2\u6570\u4e00\u6a21\u4e00\u6837\uff0c\u6240\u4ee5\u8fd9\u91cc\u4e0d\u518d\u8d58\u8ff0\u4e86\u3002<\/p>\n<p>\u4e0d\u8fc7\u6211\u4eec\u4e4b\u524d\u8bf4\u8fc7\uff0c\u8def\u5f84\u53c2\u6570\u5e94\u8be5\u5728\u67e5\u8be2\u53c2\u6570\u7684\u524d\u9762\uff0c\u5c3d\u7ba1 FastAPI \u6ca1\u6709\u8fd9\u4e2a\u8981\u6c42\uff0c\u4f46\u662f\u8fd9\u6837\u5199\u660e\u663e\u66f4\u8212\u670d\u4e00\u4e9b\u3002\u4e0d\u8fc7\u95ee\u9898\u6765\u4e86\uff0c\u5982\u679c\u8def\u5f84\u53c2\u6570\u9700\u8981\u6307\u5b9a\u522b\u540d\uff0c\u4f46\u662f\u67d0\u4e00\u4e2a\u67e5\u8be2\u53c2\u6570\u4e0d\u9700\u8981\uff0c\u8fd9\u4e2a\u65f6\u5019\u5c31\u4f1a\u51fa\u73b0\u95ee\u9898\uff1a<\/p>\n<pre><code class=\"language-python\">@app.get(&quot;\/items\/{item-id}&quot;)\nasync def read_items(\n    q: str,\n    item_id: int = Path(..., alias=&quot;item-id&quot;)\n):\n\n    return {&quot;item_id&quot;: item_id, &quot;q&quot;: q}<\/code><\/pre>\n<p>\u663e\u7136\u6b64\u65f6 Python \u7684\u8bed\u6cd5\u5c31\u51b3\u5b9a\u4e86 item_id \u5fc5\u987b\u653e\u5728 q \u7684\u540e\u9762\uff0c\u5f53\u7136\u8fd9\u4e48\u505a\u662f\u5b8c\u5168\u6ca1\u6709\u95ee\u9898\u7684\uff0cFastAPI \u5bf9\u53c2\u6570\u7684\u5148\u540e\u987a\u5e8f\u6ca1\u6709\u4efb\u4f55\u8981\u6c42\uff0c\u56e0\u4e3a\u5b83\u662f\u901a\u8fc7\u53c2\u6570\u7684\u540d\u79f0\u3001\u7c7b\u578b\u548c\u9ed8\u8ba4\u503c\u58f0\u660e\u6765\u68c0\u6d4b\u53c2\u6570\uff0c\u800c\u4e0d\u5728\u4e4e\u53c2\u6570\u7684\u987a\u5e8f\u3002\u4f46\u5982\u679c\u6211\u4eec\u5c31\u8981\u8ba9 item_id \u5728 q \u7684\u524d\u9762\u8981\u600e\u4e48\u505a\u5462\uff1f<\/p>\n<pre><code class=\"language-python\">@app.get(&quot;\/items\/{item-id}&quot;)\nasync def read_items(\n    *,\n    item_id: int = Path(..., alias=&quot;item-id&quot;),\n    q: str,\n):\n\n    return {&quot;item_id&quot;: item_id, &quot;q&quot;: q}<\/code><\/pre>\n<p>\u6b64\u65f6\u5c31\u6ca1\u6709\u95ee\u9898\u4e86\uff0c\u901a\u8fc7\u5c06\u7b2c\u4e00\u4e2a\u53c2\u6570\u8bbe\u7f6e\u4e3a *\uff0c\u4f7f\u5f97 item_id \u548c q \u90fd\u5fc5\u987b\u901a\u8fc7\u5173\u952e\u5b57\u53c2\u6570\u4f20\u9012\uff0c\u6240\u4ee5\u6b64\u65f6\u9ed8\u8ba4\u53c2\u6570\u5728\u975e\u9ed8\u8ba4\u53c2\u6570\u4e4b\u524d\u4e5f\u662f\u5141\u8bb8\u7684\u3002\u5f53\u7136\u6211\u4eec\u4e5f\u4e0d\u9700\u8981\u62c5\u5fc3 FastAPI \u4f20\u53c2\u7684\u95ee\u9898\uff0c\u4f60\u53ef\u4ee5\u8ba4\u4e3a\u5b83\u6240\u6709\u7684\u53c2\u6570\u90fd\u662f\u901a\u8fc7\u5173\u952e\u5b57\u53c2\u6570\u7684\u65b9\u5f0f\u4f20\u9012\u7684\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1.\u5b89\u88c5 \u4f7f\u7528 FastAPI \u9700\u8981 Python \u7248\u672c\u5927\u4e8e\u7b49\u4e8e 3.6 \u5b89\u88c5\u5f88\u7b80\u5355\uff0c\u76f4\u63a5 pip install fastapi \u5373\u53ef   \u2026 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0},"categories":[115],"tags":[116,16],"_links":{"self":[{"href":"\/index.php?rest_route=\/wp\/v2\/posts\/1380"}],"collection":[{"href":"\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1380"}],"version-history":[{"count":2,"href":"\/index.php?rest_route=\/wp\/v2\/posts\/1380\/revisions"}],"predecessor-version":[{"id":1391,"href":"\/index.php?rest_route=\/wp\/v2\/posts\/1380\/revisions\/1391"}],"wp:attachment":[{"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1380"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1380"},{"taxonomy":"post_tag","embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1380"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}