-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
51 lines (34 loc) · 993 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from fastapi import FastAPI
from typing import Optional
from pydantic import BaseModel
import uvicorn
app=FastAPI()
class Item(BaseModel):
id:int
name:str
age:int
salary:Optional[int]
phone:int
@app.get('/')
def index():
return {'data':'blog list'}
@app.get('/blog/unpublished')
def get_unpublished():
return {'data':'unpublished'}
@app.get('/allblogs')
def display_blogs(limit=10, sort:Optional[str]=None,published:bool=True):
if published:
return {'data':f'Displaying published blogs which are sorted in {sort} order'}
else:
return {'data': f'Diplsaying all blogs which are sorted in {sort} order'}
@app.get('/blog/{id}')
def show_blog(id:int):
return {'data': id}
@app.get('/blog/{id}/comment')
def show_comments(id:int):
return {'data':f'comments of {id}'}
@app.post('/postblog')
def post_blog(item:Item):
return {'data':f'name: {item.name}'}
if __name__=='__main__':
uvicorn.run(app,port=9000)