File tree 4 files changed +26
-4
lines changed
4 files changed +26
-4
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,9 @@ pip3 install -r requirements.txt
22
22
23
23
# run project with uvicorn
24
24
uvicorn " fastapi_project.main:app" --reload --port=8000
25
+
26
+ # or, run bash with shell
27
+ ./run_fastapi_project.sh
25
28
```
26
29
27
30
# deploy on production
@@ -35,4 +38,11 @@ uvicorn "fastapi_project.main:app" --reload --port=8000
35
38
36
39
set the environment variable
37
40
* ` DATABASE_URL `
38
- * ` LOAD_SQL_PROJECT ` value will be ` yes `
41
+ * ` LOAD_SQL_PROJECT ` value will be ` yes `
42
+
43
+ ## Project route
44
+
45
+ ``` bash
46
+ http://localhost:8000/api/v1/users
47
+ http://localhost:8000/health
48
+ ```
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 2
2
from fastapi import FastAPI
3
3
from dotenv import load_dotenv
4
4
from fastapi .middleware .cors import CORSMiddleware
5
- from fastapi_project .api import root_index
5
+ from fastapi_project .api import health , root_index
6
6
7
7
# Load .env file
8
8
load_dotenv ()
14
14
def create_application ():
15
15
application = FastAPI ()
16
16
17
- # Include the root index router
17
+ # Include the root index and health router
18
18
application .include_router (root_index .router )
19
+ application .include_router (health .router , prefix = "/health" )
19
20
20
21
21
22
if load_sql_project == True :
22
23
print ("SQL_PROJECT is enabled" )
23
24
# Include additional routers if LOAD_SQL_PROJECT is enabled
24
25
from fastapi_project .api .v1 import user
25
- application .include_router (user .router )
26
+ application .include_router (user .router , prefix = "/api/v1" )
26
27
27
28
# Add CORS middleware
28
29
# In production, replace the "*" with the actual frontend URL
File renamed without changes.
You can’t perform that action at this time.
0 commit comments