Hereβs a well-structured assignment for Day 1: Foundation and First Steps with FastAPI, designed to reinforce key concepts through hands-on practice and reflection:
π Assignment: Day 1 β Foundation and First Steps with FastAPI#
π― Objective#
By the end of this assignment, you should be able to:
Set up a FastAPI project environment
Create and run a basic FastAPI application
Understand and explore FastAPIβs automatic documentation features
π Tasks#
1. Environment Setup#
Create a new project folder named
fastapi_day1Set up a virtual environment and activate it
Install FastAPI and Uvicorn:
pip install fastapi uvicorn
2. Create Your First FastAPI App#
Create a file named
main.pyImplement a basic FastAPI app with one route:
from fastapi import FastAPI app = FastAPI() @app.get("/") def read_root(): return {"message": "Hello, FastAPI!"}
3. Run and Explore#
Run the app using:
uvicorn main:app --reload
Open your browser and explore:
Swagger UI at
http://127.0.0.1:8000/docsReDoc at
http://127.0.0.1:8000/redoc
4. Add Another Endpoint#
Add a new route
/hello/{name}that returns a personalized greeting using a path parameter.
5. Reflection Questions#
Write short answers (2β3 sentences each):
What are the key benefits of using FastAPI over Flask or Django for APIs?
How does FastAPI use Python type hints to improve development?
What did you find most interesting or surprising about the auto-generated docs?
π Submission#
Submit the following:
main.pyfileScreenshot of Swagger UI showing both endpoints
Answers to the reflection questions in a
.txtor.mdfile
Would you like me to generate a downloadable version of this assignment (PDF or Markdown)?