Skip to content

Commit 7429069

Browse files
committed
posts
1 parent b2887a9 commit 7429069

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed
326 Bytes
Binary file not shown.

API/main.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
from fastapi import FastAPI
22
from fastapi.params import Body
3+
from pydantic import BaseModel
4+
from typing import Optional
35
app = FastAPI()
46

7+
class Post(BaseModel):
8+
title: str
9+
content: str
10+
published: bool = True
11+
rating: Optional[int] = None
512

613
@app.get("/")
714
def root():
815
return {"message": "Welcome to my API"}
916

10-
@app.get("/post")
17+
@app.get("/posts")
1118
def get_posts():
1219
return {"data": "this is your post"}
1320

14-
@app.post("/createpost")
15-
def create_post(payload: dict = Body(...)):
16-
print(payload)
17-
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

Comments
 (0)