We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b2887a9 commit 7429069Copy full SHA for 7429069
API/__pycache__/main.cpython-39.pyc
326 Bytes
API/main.py
@@ -1,17 +1,25 @@
1
from fastapi import FastAPI
2
from fastapi.params import Body
3
+from pydantic import BaseModel
4
+from typing import Optional
5
app = FastAPI()
6
7
+class Post(BaseModel):
8
+ title: str
9
+ content: str
10
+ published: bool = True
11
+ rating: Optional[int] = None
12
13
@app.get("/")
14
def root():
15
return {"message": "Welcome to my API"}
16
-@app.get("/post")
17
+@app.get("/posts")
18
def get_posts():
19
return {"data": "this is your post"}
20
-@app.post("/createpost")
-def create_post(payload: dict = Body(...)):
- print(payload)
- return {"message": "this is my first post"}
21
+@app.post("/posts")
22
+def create_post(post: Post):
23
+ print(post.dict())
24
+ return {"data": post}
25
+
0 commit comments