diff --git a/.gitignore b/.gitignore index e9281a1..7250984 100644 --- a/.gitignore +++ b/.gitignore @@ -138,4 +138,4 @@ __azurite_db*__.json # Serverless directories .serverless node_modules -aws_lambda_fastapi_venv \ No newline at end of file +.aws_lambda_fastapi_venv \ No newline at end of file diff --git a/README.md b/README.md index 891483f..f8eebdc 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,9 @@ pip3 install -r requirements.txt # run project with uvicorn uvicorn "fastapi_project.main:app" --reload --port=8000 + +# or, run bash with shell +./run_fastapi_project.sh ``` # deploy on production @@ -33,11 +36,12 @@ uvicorn "fastapi_project.main:app" --reload --port=8000 set secrets `SERVERLESS_ACCESS_KEY` , `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` ## serverless -* set your data + +* set your own data ```bash # serverless.yml -org: code4mk +org: **** app: demo-app-api-fastapi service: demo-app-api-fastapi ``` @@ -49,4 +53,9 @@ service: demo-app-api-fastapi ``` +# project route +```bash +http://localhost:8000/api/v1/users +http://localhost:8000/health +``` diff --git a/fastapi_project/api/health.py b/fastapi_project/api/health.py new file mode 100644 index 0000000..d00c499 --- /dev/null +++ b/fastapi_project/api/health.py @@ -0,0 +1,11 @@ +from fastapi import APIRouter, status +from fastapi.responses import JSONResponse + +# Create a api router +router = APIRouter() + +# Health check route +@router.get("/") +async def health_check(): + data = {"status": "ok"} + return JSONResponse(content=data, status_code=status.HTTP_200_OK) \ No newline at end of file diff --git a/fastapi_project/api/root_index.py b/fastapi_project/api/root_index.py index 5d249c1..36347af 100755 --- a/fastapi_project/api/root_index.py +++ b/fastapi_project/api/root_index.py @@ -1,7 +1,7 @@ from fastapi import APIRouter, status, Request from fastapi.responses import JSONResponse -# Create a FastAPI app +# Create a api router router = APIRouter() # root index diff --git a/fastapi_project/main.py b/fastapi_project/main.py index bf5873a..d3a32ed 100755 --- a/fastapi_project/main.py +++ b/fastapi_project/main.py @@ -2,7 +2,7 @@ from fastapi import FastAPI from dotenv import load_dotenv from fastapi.middleware.cors import CORSMiddleware -from fastapi_project.api import root_index +from fastapi_project.api import health, root_index # Load .env file load_dotenv() @@ -14,15 +14,16 @@ def create_application(): application = FastAPI() - # Include the root index router + # Include the root index and health router application.include_router(root_index.router) - + application.include_router(health.router, prefix="/health") + if load_sql_project == True: print("SQL_PROJECT is enabled") # Include additional routers if LOAD_SQL_PROJECT is enabled from fastapi_project.api.v1 import user - application.include_router(user.router) + application.include_router(user.router, prefix="/api/v1") # Add CORS middleware # In production, replace the "*" with the actual frontend URL