-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
51 lines (34 loc) · 1.01 KB
/
main.py
File metadata and controls
51 lines (34 loc) · 1.01 KB
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 typing import Optional
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
@app.get("/")
def index():
return {"data": "Index"}
# uery params
@app.get("/blog")
def index(limit: int = 10, published: bool = True, sort: Optional[str] = None):
if published:
return {"data": f"{limit} published Blogs from the db"}
else:
return {"data": f"{limit} Blogs from the db"}
@app.get("/blog/unpublished")
def unpublished():
return {"data": "all unpublished blogs"}
@app.get("/blog/{id}")
def show(id: int):
# fetch blog with id ~> id
return {"data": id}
@app.get("/blog/{id}/comments")
def comments(id):
# fetch commeents of blog with id
return {"data": {"1", "2", "3"}}
class Blog(BaseModel):
title: str
body: str
published: Optional[bool]
@app.post('/blog')
def create_blog(request: Blog):
return {"data": f"Post created with title as {request.title}"}
# if __name__ == "__main__":
# uvicorn.run(app, host="127.0.0.1", port="9000")