This commit enhances the Technical Design Document (Design Docs/TDD.md) by providing explicit instructions for running the FastAPI server, pertinent to the completion of Phase 4 ("Green Implementation for FastAPI"). It also includes a minor markdown syntax correction.
Key changes:
- Added a dedicated markdown block in Phase 4 with the precise command `uvicorn app_fastapi.app:app --host 127.0.0.1 --port 8000` and context for running the FastAPI application. This makes the instruction more prominent and user-friendly.
- Removed the previous, less visible comment `# Uvicorn will run this: uvicorn app_fastapi.app:app --port 8000` from within the FastAPI Python code example to avoid redundancy and improve clarity.
- Corrected markdown code block specifiers (from ``` to ````) around the FastAPI example and the new instruction block to ensure correct rendering of the document.
These changes make it easier for anyone following the TDD to manually start and test the FastAPI server as intended at the end of Phase 4, before proceeding to the benchmarking in Phase 5.
- Includes an artificial `await asyncio.sleep(3)` (non-blocking).
- Ensure `uvicorn` runs it on the port expected by the test (e.g., 8000).
-```python
+````python
# app_fastapi/app.py (example)
from fastapi import FastAPI, Response
import asyncio
html = "<h1>Slow FastAPI Demo</h1>"
return Response(content=html, media_type="text/html")
-# Uvicorn will run this: uvicorn app_fastapi.app:app --port 8000
-```
+To run this FastAPI server manually from your project root (after ensuring `uvicorn` and `fastapi` are installed in your environment), use the following command:
+```bash
+uvicorn app_fastapi.app:app --host 127.0.0.1 --port 8000
+````
_Tests_
@app.get("/")
async def home():
await asyncio.sleep(3) # simulate slow work (non-blocking)
- html = "<h1>FastAPI Server: 3s Artificial Delay Demo</h1>"
+ html = "<h1>FastAPI Server: 3-Seconds Artificial Delay Demo</h1>"
return Response(content=html, media_type="text/html")
\ No newline at end of file
@app.route("/")
def home():
time.sleep(3) # simulate slow work
- html = "<h1>Flask Server: 3s Artificial Delay Demo</h1>" # Updated content
+ html = "<h1>Flask Server: 3-Seconds Artificial Delay Demo</h1>" # Updated content
return Response(html, mimetype="text/html")
if __name__ == "__main__":
async with httpx.AsyncClient(timeout=10) as client:
r = await client.get(f"http://{HOST}:{PORT}/")
assert r.status_code == 200
- assert "<h1>FastAPI Server: 3s Artificial Delay Demo</h1>" in r.text # Expected content
+ assert "<h1>FastAPI Server: 3-Seconds Artificial Delay Demo</h1>" in r.text # Expected content
finally:
if server_process and server_process.is_alive():
server_process.terminate() # Send SIGTERM
}
r = httpx.get("http://127.0.0.1:3000/", timeout=10, headers=headers)
assert r.status_code == 200
- assert "<h1>Flask Server: 3s Artificial Delay Demo</h1>" in r.text
+ assert "<h1>Flask Server: 3-Seconds Artificial Delay Demo</h1>" in r.text
finally:
proc.terminate()
try: