A Spring Boot based Quiz Management System where you can:
- Create quizzes
- Add questions and options
- Submit answers
- Get scoring based on correct/incorrect answers
This project demonstrates REST API development with Spring Boot, JPA, MySQL and testing using Postman.
- Create a quiz
- Add questions to a quiz (Single choice, Multiple choice, Text based)
- Fetch all quizzes
- Fetch questions of a quiz
- Submit quiz answers and calculate score
- Java 17+
- Spring Boot 3+
- Spring Data JPA
- MySQL
- Postman (for testing APIs)
git clone https://github.com/<anishasaid>/quiz-api.git
cd quiz-api
Create a database in MySQL:
CREATE DATABASE quizdb;
Update your application.properties (or application.yml) with your DB credentials:
spring.datasource.url=jdbc:mysql://localhost:3306/quizdb
spring.datasource.username=root
spring.datasource.password=your_password
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
./mvnw spring-boot:run
Application will start at: 👉 http://localhost:8080
Create Quiz
POST /api/quizzes
Request body
{
"title": "Java Basics Quiz"
}
Add Question to Quiz
POST /api/quizzes/{quizId}/questions
Request body
{
"text": "Which of these is not a primitive type?",
"type": "SINGLE_CHOICE",
"options": [
{"text": "int", "correct": false},
{"text": "String", "correct": true},
{"text": "float", "correct": false},
{"text": "boolean", "correct": false}
]
}
Fetch All Quizzes
GET /api/quizzes
Fetch Questions of a Quiz
GET /api/quizzes/{quizId}/questions
Submit Quiz
POST /api/quizzes/{quizId}/submissions
Request body
{
"answers": [
{ "questionId": 2, "selectedOptionIds": [2] },
{ "questionId": 3, "selectedOptionIds": [6] },
{ "questionId": 4, "selectedOptionIds": [11] }
]
}
Response
{
"score": 3,
"total": 3
}
- Import the endpoints into Postman.
- Start your Spring Boot app.
- Run requests step by step : Create quiz → Add questions → Fetch quizzes → Fetch questions → Submit answers.
src/main/java/com/example/quiz
┣ controller/ # REST Controllers
┣ service/ # Business logic
┣ entity/ # JPA Entities
┣ repository/ # Spring Data JPA Repos
┣ dto/ # DTOs (Request/Response)
┗ QuizApplication.java