diff --git a/Docs/Services/FastAPI/01-Setup.md b/Docs/Services/FastAPI/01-Setup.md new file mode 100644 index 0000000..f84e794 --- /dev/null +++ b/Docs/Services/FastAPI/01-Setup.md @@ -0,0 +1,12 @@ +```bash +python3 -m venv .venv +``` + + +```bash +pip install fastapi +``` + +```bash +pip freeze > requirment.txt +``` \ No newline at end of file diff --git a/Docs/Services/FastAPI/02-Simple-Route.md b/Docs/Services/FastAPI/02-Simple-Route.md new file mode 100644 index 0000000..9bb6640 --- /dev/null +++ b/Docs/Services/FastAPI/02-Simple-Route.md @@ -0,0 +1,21 @@ +```python +from fastapi import FastAPI + +app = FastAPI() + + +@app.get("/") +def home_dir(): + return {"message": "Home Pag"} +``` + +```bash +fastapi dev main.py +``` +use uvicorn as defualt runner +or +we can run with uvicorn command +```bash +uvicorn main:app --reload --host 0.0.0.0 --port 1234 +``` + diff --git a/Docs/Services/FastAPI/03-Get-Post-Json.md b/Docs/Services/FastAPI/03-Get-Post-Json.md new file mode 100644 index 0000000..c8f6480 --- /dev/null +++ b/Docs/Services/FastAPI/03-Get-Post-Json.md @@ -0,0 +1,27 @@ +```python + +from fastapi import FastAPI + +app = FastAPI() + +users = [ + {'name': 'abbas ' , 'age': '20'}, + {'name': 'mmd ' , 'age': '37'}, + {'name': 'asghar ' , 'age': '19'} +] + +@app.get("/") +def root_dir: + return {'message' , 'api is working'} + +@app.get("/users") +def home_dir(): + return users + +@app.get("/user/{name_input}") +def read_item(name_input: str): + for item in users: + if item["name"] == name_input: + return {"information": item} + return {"message" , "not worked"} +``` \ No newline at end of file