File tree Expand file tree Collapse file tree 5 files changed +29
-8
lines changed Expand file tree Collapse file tree 5 files changed +29
-8
lines changed Original file line number Diff line number Diff line change @@ -138,4 +138,4 @@ __azurite_db*__.json
138138# Serverless directories
139139.serverless
140140node_modules
141- aws_lambda_fastapi_venv
141+ . aws_lambda_fastapi_venv
Original file line number Diff line number Diff line change @@ -24,6 +24,9 @@ pip3 install -r requirements.txt
2424
2525# run project with uvicorn
2626uvicorn " fastapi_project.main:app" --reload --port=8000
27+
28+ # or, run bash with shell
29+ ./run_fastapi_project.sh
2730```
2831
2932# deploy on production
@@ -33,11 +36,12 @@ uvicorn "fastapi_project.main:app" --reload --port=8000
3336set secrets ` SERVERLESS_ACCESS_KEY ` , ` AWS_ACCESS_KEY_ID ` and ` AWS_SECRET_ACCESS_KEY `
3437
3538## serverless
36- * set your data
39+
40+ * set your own data
3741
3842``` bash
3943# serverless.yml
40- org: code4mk
44+ org: ****
4145app: demo-app-api-fastapi
4246service: demo-app-api-fastapi
4347```
@@ -49,4 +53,9 @@ service: demo-app-api-fastapi
4953```
5054
5155
56+ # project route
5257
58+ ``` bash
59+ http://localhost:8000/api/v1/users
60+ http://localhost:8000/health
61+ ```
Original file line number Diff line number Diff line change 1+ from fastapi import APIRouter , status
2+ from fastapi .responses import JSONResponse
3+
4+ # Create a api router
5+ router = APIRouter ()
6+
7+ # Health check route
8+ @router .get ("/" )
9+ async def health_check ():
10+ data = {"status" : "ok" }
11+ return JSONResponse (content = data , status_code = status .HTTP_200_OK )
Original file line number Diff line number Diff line change 11from fastapi import APIRouter , status , Request
22from fastapi .responses import JSONResponse
33
4- # Create a FastAPI app
4+ # Create a api router
55router = APIRouter ()
66
77# root index
Original file line number Diff line number Diff line change 22from fastapi import FastAPI
33from dotenv import load_dotenv
44from fastapi .middleware .cors import CORSMiddleware
5- from fastapi_project .api import root_index
5+ from fastapi_project .api import health , root_index
66
77# Load .env file
88load_dotenv ()
1414def create_application ():
1515 application = FastAPI ()
1616
17- # Include the root index router
17+ # Include the root index and health router
1818 application .include_router (root_index .router )
19-
19+ application .include_router (health .router , prefix = "/health" )
20+
2021
2122 if load_sql_project == True :
2223 print ("SQL_PROJECT is enabled" )
2324 # Include additional routers if LOAD_SQL_PROJECT is enabled
2425 from fastapi_project .api .v1 import user
25- application .include_router (user .router )
26+ application .include_router (user .router , prefix = "/api/v1" )
2627
2728 # Add CORS middleware
2829 # In production, replace the "*" with the actual frontend URL
You can’t perform that action at this time.
0 commit comments