-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
50 lines (41 loc) · 1.54 KB
/
Copy pathapp.py
File metadata and controls
50 lines (41 loc) · 1.54 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
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from datetime import datetime
app = FastAPI(title="Superpowers SaaS", description="Agentic skills framework for developers")
class User(BaseModel):
username: str
superpower: str
level: int
# Mock data
users_db = {
"alice": {"username": "alice", "superpower": "invisibility", "level": 3},
"bob": {"username": "bob", "superpower": "telepathy", "level": 5}
}
@app.get("/health")
async def health_check():
return {"status": "ok", "timestamp": datetime.now()}
@app.get("/users/{username}", response_model=User)
async def get_user(username: str):
user = users_db.get(username)
if not user:
raise HTTPException(status_code=404, detail="User not found")
return user
@app.post("/users/", response_model=User)
async def create_user(user: User):
if user.username in users_db:
raise HTTPException(status_code=400, detail="User already exists")
users_db[user.username] = user.dict()
return user
@app.put("/users/{username}", response_model=User)
async def update_user(username: str, user: User):
if username not in users_db:
raise HTTPException(status_code=404, detail="User not found")
users_db[username] = user.dict()
return user
@app.delete("/users/{username}")
async def delete_user(username: str):
if username not in users_db:
raise HTTPException(status_code=404, detail="User not found")
del users_db[username]
return {"detail": "User deleted successfully"}
# Run with: uvicorn filename:app --reload