-
Notifications
You must be signed in to change notification settings - Fork 1
Web Quiz Engine
On the Internet, you can often find sites where you need to answer some questions. It can be educational sites, sites with psychological tests, job search services, or just entertaining sites like web quests. The common thing for them is the ability to answer questions (or quizzes) and then see some results. In this project, we developed a multi-user web service for creating and solving such quizzes. The following sections describe the service.
Web Quiz Engine is a RESTful quiz service. A user can:
- Register to the service
- Get all quizzes in the service (using pagination)
- Get a specific quiz
- Post a new quiz to the service
- Solve a quiz
- Get all completed quizzes (using pagination)
- Update a self-created quiz
- Delete a self-created quiz
2 to 8 requires the user to be authenticated.
Authentication is implemented using HTTP BasicAuth. All of the data is communicated using JSON only.
Passwords are encrypted using BCrypt encoder before storing into database.
Registers email and password with the service.
POST
email and password to /api/register
Status Code | Response data |
---|---|
200 | |
400 | Email is already taken |
400 | Password must be at least 5 characters long |
400 | Given string is not a valid email |
POST
to /api/register
with content:
{
"email": "[email protected]",
"password": "something"
}
Responds with status code 200
without any content.
Retrieves quizzes from the service
GET
to /api/quizzes
with optional query parameters page
and pageSize
.
If query parameters are not provided, default values page = 0
and pageSize = 10
are used.
GET
to /api/quizzes?page=0&pageSize=5
with auth credentials
Paginated response with given parameters and status code 200
{
"content": [
{
"id": 1,
"title": "Quadrupedal animals",
"text": "Which of the following animals have 4 legs?",
"options": [
"cat",
"snake",
"hen",
"dog",
"human"
]
},
{
"id": 2,
"title": "Indian cities",
"text": "Which of the following cities are located in India?",
"options": [
"California",
"Bangalore",
"Hyderabad",
"Tokyo"
]
}
],
"pageable": {
"sort": {
"sorted": false,
"unsorted": true,
"empty": true
},
"offset": 0,
"pageSize": 5,
"pageNumber": 0,
"paged": true,
"unpaged": false
},
"last": true,
"totalPages": 1,
"totalElements": 2,
"size": 5,
"sort": {
"sorted": false,
"unsorted": true,
"empty": true
},
"number": 0,
"numberOfElements": 2,
"first": true,
"empty": false
}
Retrieves a specific quiz from the service.
GET
to /api/quizzes/{id}
Status Code | Response data |
---|---|
200 |
Quiz with id
|
404 | Requested quiz with id: {id} is not present |
GET
to /api/quizzes/1
with auth credentials
Quiz with id = 1
and status code 200
{
"id": 1,
"title": "Quadrupedal animals",
"text": "Which of the following animals have 4 legs?",
"options": [
"cat",
"snake",
"hen",
"dog",
"human"
]
}
Posts a quiz to the service
POST
quiz to /api/quizzes
title
and text
must not be blank and options
must contain more than one string. 400
will be returned upon failing these constraints.
answer
can be empty or not provided at all, in which case it is considered to be empty ([]
, i.e., all options are wrong).
POST
to /api/quizzes
with auth credentials and content:
{
"title": "Indian cities",
"text": "Which of the following cities are located in India?",
"options": ["California", "Bangalore", "Hyderabad", "Tokyo"],
"answer": [1, 2]
}
Created quiz with id and status code 200
{
"id": 2,
"title": "Indian cities",
"text": "Which of the following cities are located in India?",
"options": [
"California",
"Bangalore",
"Hyderabad",
"Tokyo"
]
}
Solves a quiz
POST
answer to /api/quizzes/{id}/solve
Status Code | Response data |
---|---|
200 | Quiz result |
404 | Requested quiz with id: {id} is not present |
For correct answer:
{
"success": true,
"feedback": "Congratulations, you're right!"
}
For wrong answer:
{
"success": false,
"feedback": "Wrong answer! Please, try again."
}
POST
to /api/quizzes/1/solve
with auth credentials and content:
{
"answer": [0, 3, 4]
}
Quiz result with status code 200
{
"success": true,
"feedback": "Congratulations, you're right!"
}
Retrieves all id's of quizzes completed by this user (email).
GET
to /api/quizzes/completed
with query parameters page
and pageSize
.
If query parameters are not provided, default values page = 0
and pageSize = 10
are used.
Response includes multiple successful submissions for the same quiz.
GET
to /api/quizzes/completed?page=0&pageSize=10
with auth credentials
Paginated response with given parameters and status code 200
{
"content": [
{
"id": 1,
"completedAt": "2020-07-28T06:44:07.361+0000"
},
{
"id": 1,
"completedAt": "2020-07-28T06:40:11.535+0000"
}
],
"pageable": {
"sort": {
"sorted": true,
"unsorted": false,
"empty": false
},
"offset": 0,
"pageSize": 10,
"pageNumber": 0,
"paged": true,
"unpaged": false
},
"last": true,
"totalPages": 1,
"totalElements": 2,
"size": 10,
"sort": {
"sorted": true,
"unsorted": false,
"empty": false
},
"number": 0,
"numberOfElements": 2,
"first": true,
"empty": false
}
Updates the specified quiz
PUT
updated quiz to /api/quizzes/{id}
As with Posting a quiz, title
and text
must not be blank and options
must contain more than one string. 400
will be returned upon failing these constraints. answer
can be empty or not provided at all, in which case it is considered to be empty ([]
, i.e., all options are wrong).
If this user (email) is not the creator of the quiz, status code 403
will be returned. If the quiz with id
is not found, a new quiz will be created and that quiz will be returned with status code 201
Status Code | Response data |
---|---|
200 | Updated Quiz with id
|
201 | Created Quiz with id
|
403 |
PUT
to /api/quizzes/2
with auth credentials and content:
{
"title": "Indian cities (Updated)",
"text": "Which of the following cities are located in India?",
"options": ["California", "Bangalore", "Hyderabad", "Tokyo", "Vijayawada"],
"answer": [1, 2, 4]
}
Updated quiz with id
and status code 200
{
"id": 2,
"title": "Indian cities (Updated)",
"text": "Which of the following cities are located in India?",
"options": [
"California",
"Bangalore",
"Hyderabad",
"Tokyo",
"Vijayawada"
]
}
Deletes the specified quiz
DELETE
to /api/quizzes/{id}
Returns 204
if the quiz is deleted successfully.
If this user (email) is not the creator of the quiz, status code 403
will be returned.
DELETE
to /api/quizzes/1
with auth credentials
Responds with status code 204
without any content
2 to 8 requires the user to be authenticated. If the user is not authenticated successfully, either because auth credentials are not sent or because they do not match, the service will respond with 401
application.properties
server.port=8080
management.endpoints.web.exposure.include=*
management.endpoint.shutdown.enabled=true
spring.datasource.url=jdbc:h2:file:./quizdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=admin
spring.datasource.password=admin
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=update
spring.h2.console.enabled=true
spring.h2.console.settings.trace=false
spring.h2.console.settings.web-allow-others=false
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
This project was developed as part of Hyperskill's Java Developer Track. Visit hyperskill for more details.