├── FASTAPI ├── app │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-39.pyc │ │ └── app.cpython-39.pyc │ └── app.py └── main.py ├── Fastapi_presentation.pdf ├── README.md └── structure.txt /FASTAPI/app/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BekBrace/FastAPI_Crash_Course/92ade3afc3c205695570ec47dcc013acbe13465f/FASTAPI/app/__init__.py -------------------------------------------------------------------------------- /FASTAPI/app/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BekBrace/FastAPI_Crash_Course/92ade3afc3c205695570ec47dcc013acbe13465f/FASTAPI/app/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /FASTAPI/app/__pycache__/app.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BekBrace/FastAPI_Crash_Course/92ade3afc3c205695570ec47dcc013acbe13465f/FASTAPI/app/__pycache__/app.cpython-39.pyc -------------------------------------------------------------------------------- /FASTAPI/app/app.py: -------------------------------------------------------------------------------- 1 | # Importing the FastApi class 2 | from fastapi import FastAPI 3 | 4 | # Creating an app object 5 | app = FastAPI() 6 | 7 | # Default route 8 | 9 | # A minimal app to demonstrate the get request 10 | @app.get("/", tags=['root']) 11 | async def root() -> dict: 12 | return {"Ping": "Pong"} 13 | 14 | 15 | # GET -- > Read Todo 16 | @app.get("/todo", tags=['Todos']) 17 | async def get_todos() -> dict: 18 | return {"Data": todos} 19 | 20 | 21 | # Post -- > Create Todo 22 | @app.post("/todo", tags=["Todos"]) 23 | async def add_todo(todo: dict) -> dict: 24 | todos.append(todo) 25 | return { 26 | "data": "A Todo is Added!" 27 | } 28 | 29 | 30 | # PUT -- > Update Todo 31 | @app.put("/todo/{id}", tags=["Todos"]) 32 | async def update_todo(id: int, body: dict) -> dict: 33 | for todo in todos: 34 | if (int(todo["id"])) == id: 35 | todo["Activity"] = body["Activity"] 36 | return { 37 | "data": f"Todo with id {id} has been updated" 38 | } 39 | return { 40 | "data": f"This Todo with id {id} is not found!" 41 | } 42 | 43 | 44 | # DELETE --> Delete Todo 45 | @app.delete("/todo/{id}", tags=["Todos"]) 46 | async def delete_todo(id: int) -> dict: 47 | for todo in todos: 48 | if int(todo["id"]) == id: 49 | todos.remove(todo) 50 | return{ 51 | "data": f"Todo with id {id} has been deleted!" 52 | } 53 | return { 54 | "data": f"Todo with id {id} was not found!" 55 | } 56 | 57 | # Todos List 58 | 59 | todos = [ 60 | { 61 | "id": "1", 62 | "Activity": "Jogging for 2 hours at 7:00 AM." 63 | }, 64 | { 65 | "id": "2", 66 | "Activity": "Writing 3 pages of my new book at 2:00 PM." 67 | } 68 | ] 69 | -------------------------------------------------------------------------------- /FASTAPI/main.py: -------------------------------------------------------------------------------- 1 | import uvicorn 2 | 3 | if __name__ == "__main__": 4 | uvicorn.run("app.app:app", port=8000, reload=True) 5 | -------------------------------------------------------------------------------- /Fastapi_presentation.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BekBrace/FastAPI_Crash_Course/92ade3afc3c205695570ec47dcc013acbe13465f/Fastapi_presentation.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FastAPI_CRUD_Router- 2 | This is FastAPI crash course where we created an CRUD Router on the FASTAPI interactive documents 3 | 4 | FastAPI is a modern and fast web framework for building APIs 5 | 6 | FastAPI supports concurrency and coroutines without importing asyncio package 7 | 8 | One of the fastest Python frameworks available 9 | 10 | Faster than nodeJS 11 | 12 | Designed to be easy to use and learn. Less time reading docs. 13 | 14 | Minimize code duplication (fewer bugs) 15 | 16 | FastAPI Github page : https://github.com/tiangolo/fastapi 17 | -------------------------------------------------------------------------------- /structure.txt: -------------------------------------------------------------------------------- 1 | └── FASTAPI 2 | ├── main.py 3 | └── app 4 | ├── __init__.py 5 | └── app.py --------------------------------------------------------------------------------