├── requirements.txt ├── README.md └── main.py /requirements.txt: -------------------------------------------------------------------------------- 1 | pydantic 2 | uvicorn 3 | fastapi 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Fast-API-CRUD-App 2 | 3 | # 💻 Launch Your Software Development Career Today! 4 | 5 | 🎓 **No degree? No problem!** My program equips you with everything you need to break into tech and land an entry-level software development role. 6 | 7 | 🚀 **Why Join?** 8 | - 💼 **$70k+ starting salary potential** 9 | - 🕐 **Self-paced:** Complete on your own time 10 | - 🤑 **Affordable:** Low risk compared to expensive bootcamps or degrees 11 | - 🎯 **45,000+ job openings** in the market 12 | 13 | 👉 **[Start your journey today!](https://techwithtim.net/dev)** 14 | No experience needed—just your determination. Future-proof your career and unlock six-figure potential like many of our students have! 15 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | from fastapi import FastAPI, HTTPException 2 | from pydantic import BaseModel 3 | from typing import List, Optional 4 | from uuid import UUID, uuid4 5 | 6 | app = FastAPI() 7 | 8 | class Task(BaseModel): 9 | id: Optional[UUID] = None 10 | title: str 11 | description: Optional[str] = None 12 | completed: bool = False 13 | 14 | tasks = [] 15 | 16 | @app.post("/tasks/", response_model=Task) 17 | def create_task(task: Task): 18 | task.id = uuid4() 19 | tasks.append(task) 20 | return task 21 | 22 | 23 | @app.get("/tasks/", response_model=List[Task]) 24 | def read_tasks(): 25 | return tasks 26 | 27 | @app.get("/tasks/{task_id}", response_model=Task) 28 | def read_task(task_id: UUID): 29 | for task in tasks: 30 | if task.id == task_id: 31 | return task 32 | 33 | raise HTTPException(status_code=404, detail="Task not found") 34 | 35 | @app.put("/tasks/{task_id}", response_model=Task) 36 | def update_task(task_id: UUID, task_update: Task): 37 | for idx, task in enumerate(tasks): 38 | if task.id == task_id: 39 | updated_task = task.copy(update=task_update.dict(exclude_unset=True)) 40 | tasks[idx] = updated_task 41 | return updated_task 42 | 43 | raise HTTPException(status_code=404, detail="Task not found") 44 | 45 | @app.delete("/tasks/{task_id}", response_model=Task) 46 | def delete_task(task_id: UUID): 47 | for idx, task in enumerate(tasks): 48 | if task.id == task_id: 49 | return tasks.pop(idx) 50 | 51 | raise HTTPException(status_code=404, detail="Task not found") 52 | 53 | 54 | if __name__ == "__main__": 55 | import uvicorn 56 | 57 | uvicorn.run(app, host="0.0.0.0", port=8000) --------------------------------------------------------------------------------