Module 1 of 9 · Lesson 1 of 26
Build your first synchronous HTTP endpoint
Work through build your first synchronous HTTP endpoint using a runnable reference, a focused regression check and a local extension.
Read in any order. All lessons stay open, including after an unanswered or incorrect check.
Keep the first example small enough to explain from request to response. The id is taken from the path, while the name and availability are deliberately fixed demonstration data. Nothing is persisted, so this endpoint must not claim to show live stock. Uvicorn serves the application; FastAPI chooses the route, validates its input and serializes its output. An HTTP client sees the status, headers and body, rather than the Python implementation.
Start python -m uvicorn equipment.hello:app --port 8000 from the extracted lab directory. Request /equipment/7, /equipment/not-an-integer and POST /equipment/7. Predict the three statuses, then inspect them. Stop the server before running the lesson check. Its assertions verify 200-style success, 422 validation and 405 method rejection.
@app.get("/equipment/{equipment_id}")
def describe(equipment_id: int):
return {"id": equipment_id, "name": "Tripod", "available": True}
python run_checks.py -k lesson01
Expected result The selected lesson test passes against a new temporary PostgreSQL database; the container is removed afterward.
Keep for reference
Equipment Rental lab and lesson checks
ZIP containing Python source, real Alembic migrations, 26 lesson checks, a dependency lock and text instructions. Extract it before following the local exercise.
Practise locally
Add GET /equipment/{equipment_id}/availability in your own copy. Return the same integer id and a clearly labeled demonstration availability value. Add a TestClient assertion for a valid id and a second assertion for invalid text. Keep the original route working. Save the test output and explain which input is validated before your function runs.
The lesson check verifies the reference behavior. Add your own assertions for your change. Local practice is not uploaded or scored by this learning release.
Pause and reflect
What failure does this lesson prevent, and which assertion in lesson01 would expose it?
Use a concrete input, expected result and limitation from your local work. Saving a reflection does not certify the project.
Optional knowledge check
Why does /equipment/not-an-integer fail before describe runs?
The int path annotation rejects invalid input.
Correct. FastAPI validates the annotated path before calling the endpoint.
The demonstration stock record cannot be found.
Try another answer. This first example has no database lookup; the failure concerns the path contract.
The HTTP client validates the path only after the server returns.
Try another answer. Server-side annotated validation happens before the endpoint runs.
This practice does not assess your project or award a certificate.
Your reading progress
Progress is saved in this browser when storage is available.