I wanted to use everything I have been learning for the past couple of months to use and make something simple including as much of everything as I could.
QuizApp is a Spring Boot-based web application designed to manage quizzes. The application allows users to create, retrieve, and submit quizzes. It uses a RESTful API with full CRUD operations and interacts with a MySQL database. This project also supports user quiz submissions and score calculation.
git clone https://github.com/hxvMI/Spring_Boot_Quiz_Application.git
cd quizapp
mvn spring-boot:run
src/main/java/com/vhashiro/quizapp
├── controller # Contains API controllers
├── entity # Defines JPA entities
├── repository # Database access with JPA
├── service # Business logic and services
├── QuizAppApplication.java # Spring Boot main class
└── application.properties # Configuration file
Ensure your MySQL server is running, and configure the application.properties file for the database connection:
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://localhost:3306/quiz_database
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
For development and testing, you can switch to an H2 in-memory database by uncommenting the following lines in application.properties
:
#spring.h2.console.enabled=true
#spring.datasource.url=jdbc:h2:mem:dcbapp
#spring.datasource.driver-class-name=org.h2.Driver
#spring.datasource.username=sa
#spring.datasource.password=password
#spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
Get all questions
/question/allQuestions
Get questions by category
/question/category/{categoryName}
Retrieves questions based on their category.Add a new question
/questions/add
Adds a new question to the database.Create a new quiz
/quiz/create?questionCategory={category}&numQuestions={numQuestions}&title={title}
Get quiz by ID
/quiz/get/{id}
Retrieves a quiz by its ID.Submit a quiz
/quiz/submit/{id}/
Submits a quiz and calculates the score based on user responses.You can use Postman or curl to test the endpoints.
curl -X POST "http://localhost:8083/quiz/create?questionCategory=java&numQuestions=5&title=JavaBasics"
curl -X POST "http://localhost:8083/quiz/submit/1" \
-H "Content-Type: application/json" \
-d '[
{"id": 1, "selectedOption": "option1"},
{"id": 2, "selectedOption": "option3"}
]'
I have also included other examples in quizapp/quizapp/src/main/java/com/vhashiro/quizapp/Request Testing Resources