Описание путей
This commit is contained in:
parent
e3e0f82207
commit
0221f1255d
38
app.py
38
app.py
@ -5,37 +5,27 @@ from typing import List, Optional
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
# Модель данных
|
||||
class Item(BaseModel):
|
||||
id: int
|
||||
name: str
|
||||
module_name: str
|
||||
module_version: str
|
||||
|
||||
|
||||
# Пример данных
|
||||
data = [
|
||||
Item(id=1, name='Item 1'),
|
||||
Item(id=2, name='Item 2')
|
||||
]
|
||||
|
||||
|
||||
@app.get('/items', response_model=List[Item])
|
||||
@app.get('/', response_model=List[Item])
|
||||
def get_items():
|
||||
return data
|
||||
data_info = [Item(module_name="Crypto Licensing", module_version="1.0.0")]
|
||||
return data_info
|
||||
|
||||
# @app.get('/items/{item_id}', response_model=Optional[Item])
|
||||
# def get_item(item_id: int):
|
||||
# item = next((item for item in data if item.id == item_id), None)
|
||||
# return item
|
||||
|
||||
|
||||
@app.get('/items/{item_id}', response_model=Optional[Item])
|
||||
def get_item(item_id: int):
|
||||
item = next((item for item in data if item.id == item_id), None)
|
||||
return item
|
||||
|
||||
|
||||
@app.post('/items', response_model=Item)
|
||||
def create_item(item: Item):
|
||||
data.append(item)
|
||||
return item
|
||||
# @app.post('/items', response_model=Item)
|
||||
# def create_item(item: Item):
|
||||
# data.append(item)
|
||||
# return item
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import uvicorn
|
||||
|
||||
uvicorn.run(app, host='127.0.0.1', port=8000)
|
||||
|
Loading…
Reference in New Issue
Block a user