33I chose FastApi because it's simple, easy to create endpoints, and has automatic documentation.
44
55| Framework | Pros | Cons | Reason Not Chosen |
6- | -------------| ----------------------------------------------------- | ------------------------------------------- | --------------------------------- |
6+ | -------------| ------------------------------------------------------- | --------------------------------------------- | ----------------------------------- |
77| ** FastAPI** | Async support, type safety, OpenAPI, high performance | Slight learning curve | ** Chosen** |
88| Flask | Simple, minimal | No async by default, no built-in validation | Less suitable for structured APIs |
99| Django | Full-featured, mature | Heavy, overkill for small service | Too complex for this task |
@@ -12,46 +12,45 @@ I chose FastApi because it's simple, easy to create endpoints, and has automatic
1212
13131 . Environment-based Configuration
1414
15- ``` python
16- HOST = os.getenv(" HOST" , " 0.0.0.0" )
17- PORT = int (os.getenv(" PORT" , 5000 ))
18- DEBUG = os.getenv(" DEBUG" , " False" ).lower() == " true"
19- ```
20-
21- it important because it enables configuration without code changes.
15+ ``` text
16+ HOST = os.getenv("HOST", "0.0.0.0")
17+ PORT = int(os.getenv("PORT", 5000))
18+ DEBUG = os.getenv("DEBUG", "False").lower() == "true"
19+ ```
20+
21+ it important because it enables configuration without code changes.
2222
23232 . Separation of Concerns
2424
25- ```python
26- class HealthCheckService :
27- async def get_info (self , request : Request) -> InfoResponse:
28- ...
29-
30- ```
31-
32- it important because it easier testing, cleaner routing layer
25+ ``` text
26+ class HealthCheckService:
27+ async def get_info(self, request: Request) -> InfoResponse:
28+ pass
29+ ```
30+
31+ it important because it easier testing, cleaner routing layer
3332
34333 . Typed Responses with Pydantic
3534
36- ``` python
37- class InfoResponse (BaseModel ):
38- service: ServiceInfo
39- system: SystemInfo
40- runtime: RuntimeInfo
41- request: RequestInfo
42- endpoints: list[EndpointInfo]
43- ```
44-
45- it important because guarantees response structure and improves readability
35+ ``` text
36+ class InfoResponse(BaseModel):
37+ service: ServiceInfo
38+ system: SystemInfo
39+ runtime: RuntimeInfo
40+ request: RequestInfo
41+ endpoints: list[EndpointInfo]
42+ ```
43+
44+ it important because guarantees response structure and improves readability
4645
47464 . Logging
4847
49- ``` python
50- logger = logging.getLogger(__name__ )
51- logger.info(" Handling info request" )
52- ```
53-
54- it important because it centralized observability and works seamlessly with Uvicorn
48+ ``` text
49+ logger = logging.getLogger(__name__)
50+ logger.info("Handling info request")
51+ ```
52+
53+ it important because it centralized observability and works seamlessly with Uvicorn
5554
5655## API Documentation
5756
@@ -111,21 +110,21 @@ I chose FastApi because it's simple, easy to create endpoints, and has automatic
111110 "uptime_seconds" : 7390
112111 }
113112 ```
114-
113+
1151143 . Testing Commands
116115
117116 Using curl:
118117 ``` bash
119118 curl http://localhost:5000/
120119 curl http://localhost:5000/health
121120 ```
122-
121+
123122 or auto generated documentation:
124-
123+
125124 ``` bash
126125 http://localhost:5000/docs
127126 ```
128-
127+
129128## Testing Evidence
130129
131130- Successful responses from ` / ` and ` /health `
0 commit comments