Skip to content

Commit b6aad46

Browse files
committed
step 3
1 parent 0f58719 commit b6aad46

File tree

4 files changed

+106
-0
lines changed

4 files changed

+106
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
mode: agent
3+
description: Create a new programming homework assignment
4+
---
5+
6+
# Create New Programming Assignment
7+
8+
Your goal is to generate a new homework assignment for the Mergington High School students.
9+
10+
## Step 1: Gather Assignment Information
11+
12+
If not already provided by the user, ask what the assignment will be about.
13+
14+
## Step 2: Create Assignment Structure
15+
16+
1. Create a new directory in the `assignments` folder with a unique name based on the assignment topic
17+
1. Create a new file in the directory named `README.md` with the structure from the [assignment-template.md](../../templates/assignment-template.md) file
18+
1. Fill out the assignment details in the README file
19+
1. (Optional) Add starter code or attachments if the assignment needs them - add these files to the same assignment folder
20+
21+
## Step 3: Update Website Configuration
22+
23+
Update the assignments list in [config.json](../../config.json) website configuration file to include the new assignment. For the dueDate field, use the current date plus 7 days unless specified otherwise.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# 🚀 Assignment: Building REST APIs with FastAPI
2+
3+
## 🎯 Objective
4+
5+
Learn how to build and test RESTful APIs using the FastAPI framework in Python. You will create endpoints, handle requests and responses, and understand basic API concepts.
6+
7+
## 📝 Tasks
8+
9+
### 🛠️ Create a Simple FastAPI Application
10+
11+
#### Description
12+
Set up a FastAPI project and create a basic API with at least two endpoints.
13+
14+
#### Requirements
15+
Completed program should:
16+
- Use FastAPI to create a web server
17+
- Implement a root endpoint (`/`) that returns a welcome message
18+
- Implement a `/items/{item_id}` endpoint that returns details for a given item
19+
20+
### 🛠️ Add Data and Error Handling
21+
22+
#### Description
23+
Enhance your API to handle data and errors gracefully.
24+
25+
#### Requirements
26+
Completed program should:
27+
- Use a Python dictionary or list to store item data
28+
- Return a 404 error if an item is not found
29+
- Validate input types and handle invalid requests
30+
31+
### 🛠️ (Optional) Add a POST Endpoint
32+
33+
#### Description
34+
Allow users to add new items to your API using a POST request.
35+
36+
#### Requirements
37+
Completed program should:
38+
- Accept JSON data in the request body
39+
- Add the new item to your data store
40+
- Return a success message and the added item
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Starter code for FastAPI REST API assignment
2+
3+
from fastapi import FastAPI, HTTPException
4+
from typing import Optional
5+
6+
app = FastAPI()
7+
8+
# Example data store
9+
items = {
10+
1: {"name": "Apple", "price": 0.99},
11+
2: {"name": "Banana", "price": 0.59}
12+
}
13+
14+
@app.get("/")
15+
def read_root():
16+
return {"message": "Welcome to the FastAPI assignment!"}
17+
18+
@app.get("/items/{item_id}")
19+
def read_item(item_id: int):
20+
item = items.get(item_id)
21+
if item:
22+
return item
23+
raise HTTPException(status_code=404, detail="Item not found")
24+
25+
# (Optional) POST endpoint for adding items
26+
# @app.post("/items/")
27+
# def add_item(item: dict):
28+
# # Implement item addition logic here
29+
# pass

config.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,20 @@
5858
"type": "csv"
5959
}
6060
]
61+
},
62+
{
63+
"id": "fastapi-rest-api",
64+
"title": "Building REST APIs with FastAPI",
65+
"description": "Learn to build RESTful APIs using the FastAPI framework in Python.",
66+
"path": "assignments/fastapi-rest-api",
67+
"dueDate": "2025-10-30",
68+
"attachments": [
69+
{
70+
"name": "Starter Code",
71+
"file": "starter-code.py",
72+
"type": "python"
73+
}
74+
]
6175
}
6276
]
6377
}

0 commit comments

Comments
 (0)