This is a simple and fast API built using FastAPI that helps retrieve marks of students by their names. It reads the data from a local JSON file and supports fetching data for multiple students at once. This project is perfect for small web apps, school tools, or learning how APIs work.
- Reads student marks from a JSON file.
- Exposes a REST API to get marks based on student names.
- Allows querying one or more names at a time.
- Supports frontend apps with CORS enabled (Cross-Origin access).
Example data in the JSON file:
{"name":"4","marks":32},{"name":"z3e7J3kd","marks":6},{"name":"Lvhiq8l5kx","marks":50},{"name":"Tf3lZ0Wpf","marks":44},
{"name":"HHxcdmfu","marks":48},{"name":"SQ","marks":44},{"name":"FYS","marks":13},{"name":"3g","marks":85},
{"name":"prJ1","marks":35},{"name":"z6t","marks":70},{"name":"M","marks":42},{"name":"H","marks":64},
{"name":"enw9xo","marks":45},{"name":"ztjaio","marks":62},{"name":"g0bx","marks":76},{"name":"hXvfzH","marks":87},
{"name":"9","marks":61},{"name":"ppIjO","marks":64},{"name":"wvHvc3B0s","marks":79},{"name":"wHR5dyKyzu","marks":31},This JSON holds names and corresponding marks.
| Section | Purpose |
|---|---|
FastAPI() |
Creates the web app |
CORSMiddleware |
Allows frontend apps to fetch data |
json.load() |
Loads data from the JSON file |
@app.get("/api") |
Defines an API endpoint to get student marks |
Logic inside /api |
Splits comma-separated names, checks data, and returns marks or null |
Request:
GET /api?name=Alice,Bob
Response:
{
"marks": [95, 88]
}If a name is not found:
GET /api?name=Alice,UnknownName
Response:
{
"marks": [95, null]
}- Python 3.8 or higher
- FastAPI
- Uvicorn (ASGI server)
pip install fastapi uvicornuvicorn app:app --reloadNow open this URL in your browser or API tool like Postman:
http://127.0.0.1:8000/api?name=Alice,Bob
- Works well with serverless platforms like Vercel.
- Add a
vercel.jsonfile if needed. - Entry point (
app.py) should be ASGI-compatible.
📦 student-marks-api/
┣ 📄 app.py # Main FastAPI app
┣ 📄 q-vercel-python.json # Student data file
┗ 📄 README.md # Project documentation
- Add a POST route to insert or update marks
- Store data in a real database (e.g., MongoDB)
- Build a frontend using React or plain HTML/JS
- Add authentication to protect API access
Feel free to fork, improve, and create pull requests. All contributions are welcome!
This project is open source and free to use under the MIT License.
---