fast_api 探索
This commit is contained in:
@@ -8,9 +8,7 @@
|
|||||||
"collapsed": true
|
"collapsed": true
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": ""
|
||||||
""
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"metadata": {
|
"metadata": {
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
from typing import Union
|
||||||
|
from fastapi import FastAPI
|
||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
app = FastAPI()
|
||||||
|
|
||||||
|
class Item(BaseModel):
|
||||||
|
name: str
|
||||||
|
price: float
|
||||||
|
is_offer: Union[bool, None] = None
|
||||||
|
|
||||||
|
@app.get("/")
|
||||||
|
def read_root():
|
||||||
|
return {"Hello": "World"}
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/items/{item_id}")
|
||||||
|
def read_item(item_id: int, q: Union[str, None] = None):
|
||||||
|
return {"item_id": item_id, "q": q}
|
||||||
|
|
||||||
|
|
||||||
|
@app.put("/items/{item_id}")
|
||||||
|
def update_item(item_id: int, item: Item):
|
||||||
|
return {"item_name": item.price, "item_id": item_id}
|
||||||
|
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
<sourceFolder url="file://$MODULE_DIR$/python爬虫/python爬虫练习/wangyizhaopin" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/python爬虫/python爬虫练习/wangyizhaopin" isTestSource="false" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/python爬虫/python爬虫练习/douban" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/python爬虫/python爬虫练习/douban" isTestSource="false" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/flask框架" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/flask框架" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/Fastapi" isTestSource="false" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/python爬虫/python爬虫练习/novel" />
|
<excludeFolder url="file://$MODULE_DIR$/python爬虫/python爬虫练习/novel" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="jdk" jdkName="python" jdkType="Python SDK" />
|
<orderEntry type="jdk" jdkName="python" jdkType="Python SDK" />
|
||||||
|
|||||||
Reference in New Issue
Block a user