A simple REST API built with FastAPI and PostgreSQL for managing quiz questions and choices.
- Create questions with multiple choices
- Retrieve questions by ID
- Get choices for specific questions
- PostgreSQL database integration
- OpenAPI documentation (Swagger UI)
- Python 3.12 or higher
- Docker and Docker Compose
- Poetry (optional)
- Clone the repository:
git clone https://github.com/sergiomarquezdev/fastapi-postgresql
cd fastapi-postgresql- Install dependencies:
# Using uv (recommended)
uv pip install -e .
# Or using poetry
poetry install- Start PostgreSQL database:
docker-compose up -d- Run the FastAPI application:
uvicorn src.fastapi_postgresql.main:app --reloadThe API will be available at http://localhost:8000
Access the interactive API documentation at:
- Swagger UI:
http://localhost:8000/docs - ReDoc:
http://localhost:8000/redoc
GET /questions/{question_id}- Get a specific questionGET /choices/{question_id}- Get choices for a specific questionPOST /questions- Create a new question with choices
POST /questions
{
"question_text": "What is the capital of France?",
"choices": [
{
"choice_text": "Paris",
"is_correct": true
},
{
"choice_text": "London",
"is_correct": false
}
]
}