sh20raj commited on
Commit
ef014d1
·
1 Parent(s): 14c36bc

Refactor app.py to include user and product routers, update greeting message, and clean up commented code.

Browse files
Files changed (4) hide show
  1. app.py +6 -9
  2. routers/__init__.py +4 -0
  3. routers/products.py +11 -0
  4. routers/users.py +11 -0
app.py CHANGED
@@ -1,16 +1,13 @@
1
  from fastapi import FastAPI
 
2
 
3
  app = FastAPI()
4
 
5
- # Define a route
6
- @app.get("/api/greet")
7
- def greet(name: str = "World"):
8
- return {"message": f"Hello, {name}!"}
9
-
10
- # Run the server (use Uvicorn)
11
- # Command: uvicorn app:app --reload
12
 
13
  @app.get("/")
14
  def read_root():
15
- return {"message": "Hello from Hugging Face Spaces!"}
16
-
 
1
  from fastapi import FastAPI
2
+ from routers import users, products # Import your routers
3
 
4
  app = FastAPI()
5
 
6
+ # Include routers
7
+ app.include_router(users.router, prefix="/users", tags=["Users"])
8
+ app.include_router(products.router, prefix="/products", tags=["Products"])
9
+ # app.include_router(orders.router, prefix="/orders", tags=["Orders"])
 
 
 
10
 
11
  @app.get("/")
12
  def read_root():
13
+ return {"message": "Welcome to the API"}
 
routers/__init__.py ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ from .users import router as users_router
2
+ from .products import router as products_router
3
+
4
+ __all__ = ["users_router", "products_router"]
routers/products.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import APIRouter
2
+
3
+ router = APIRouter()
4
+
5
+ @router.get("/products")
6
+ def get_products():
7
+ return {"message": "List of products"}
8
+
9
+ @router.post("/products")
10
+ def create_product():
11
+ return {"message": "Product created"}
routers/users.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import APIRouter
2
+
3
+ router = APIRouter()
4
+
5
+ @router.get("/users")
6
+ def get_users():
7
+ return {"message": "List of users"}
8
+
9
+ @router.post("/users")
10
+ def create_user():
11
+ return {"message": "User created"}