FastAPI service for retrieving and caching college essay prompts by school name. The API combines browser automation, HTML parsing, MongoDB caching, API-key authentication, and request rate limiting into a small admissions-data backend.
This project was built as a practical education-technology API: students, counselors, and advising products can request structured essay prompt data instead of manually searching college prompt pages.
POST /get_essay_prompts/for one collegePOST /get_multiple_essay_prompts/for comma-separated college lists- Selenium-driven scraping flow for prompt discovery
- BeautifulSoup parsing into structured prompt objects
- MongoDB cache to avoid repeat scraping
- API-key check through the
x-api-keyheader - SlowAPI rate limiting at 5 requests per minute
- Azure App Service deployment workflow files
Client
-> FastAPI endpoint
-> API key validation
-> MongoDB cache lookup
-> Selenium browser scrape on cache miss
-> BeautifulSoup prompt extraction
-> MongoDB insert
-> JSON response
curl -X POST "http://localhost:8000/get_essay_prompts/" \
-H "Content-Type: application/json" \
-H "x-api-key: YOUR_API_KEY" \
-d "{\"college_name\":\"University of Washington\"}"Example response shape:
{
"college_name": "University of Washington",
"prompts": [
{
"title": "Prompt title",
"required": "Required",
"word_count": "300 words",
"description": "Prompt text",
"options": null
}
]
}Use Python 3.10 or 3.11 for the pinned dependency set.
python -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txt
uvicorn main:app --reloadThe code currently uses a placeholder MongoDB URI in main.py:
MongoClient("you_credentials")For production, move this to an environment variable such as MONGODB_URI and seed valid API keys in the api_keys collection.
Each cached college record stores:
{
"college_name": "School name",
"prompts": [
{
"title": "Prompt title",
"required": "Required or optional",
"word_count": "Word count text",
"description": "Prompt body",
"options": [
{
"option_title": "Option A",
"option_description": "Option prompt"
}
]
}
]
}Current checks performed:
python -m py_compile main.pypasses- Dependencies install from
requirements.txt - Full import check currently fails on Python 3.12 because
fastapi==0.95.2andpydantic==1.10.7are not compatible with that runtime
- Move MongoDB credentials to environment variables
- Upgrade FastAPI and Pydantic for Python 3.12 compatibility
- Replace endpoint dependency usage for the rate limiter with the recommended SlowAPI decorator pattern
- Add pytest coverage for
clean_text, parser output, cache hit/miss behavior, and auth failure cases - Add a mock scraper fixture so tests do not depend on a live browser or external website
- Add OpenAPI examples and response schemas
- Add Dockerfile plus a one-command local MongoDB setup