Skip to content

Commit 2c4f66a

Browse files
committed
Reformat code
1 parent cbe739a commit 2c4f66a

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

fastapi/books_api.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,36 @@
11
from typing import Optional
22

3-
from fastapi import FastAPI
43
from pydantic import BaseModel
54

5+
from fastapi import FastAPI
6+
67
app = FastAPI()
78

89
books = [
910
{"id": 1, "title": "Python Basics", "author": "Real P.", "pages": 635},
10-
{"id": 2, "title": "Breaking the Rules", "author": "Stephen G.", "pages": 99},
11+
{
12+
"id": 2,
13+
"title": "Breaking the Rules",
14+
"author": "Stephen G.",
15+
"pages": 99,
16+
},
1117
]
1218

19+
1320
class Book(BaseModel):
1421
title: str
1522
author: str
1623
pages: int
1724

25+
1826
@app.get("/books")
1927
def get_books(limit: Optional[int] = None):
2028
"""Get all books, optionally limited by count."""
2129
if limit:
2230
return {"books": books[:limit]}
2331
return {"books": books}
2432

33+
2534
@app.get("/books/{book_id}")
2635
def get_book(book_id: int):
2736
"""Get a specific book by ID."""
@@ -30,14 +39,15 @@ def get_book(book_id: int):
3039
return book
3140
return {"error": "Book not found"}
3241

42+
3343
@app.post("/books")
3444
def create_book(book: Book):
3545
"""Create a new book entry."""
3646
new_book = {
3747
"id": len(books) + 1,
3848
"title": book.title,
3949
"author": book.author,
40-
"pages": book.pages
50+
"pages": book.pages,
4151
}
4252
books.append(new_book)
4353
return new_book

fastapi/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
app = FastAPI()
44

5+
56
@app.get("/")
67
def home():
78
return {"message": "Hello, FastAPI!"}

0 commit comments

Comments
 (0)