The Voter Spring Boot RESTful Web Service is used for Springboot testing. The Voter service exposes several HTTP API endpoints, listed below. API users can review a static list votes , cast a vote, view voting results.
The Voter service can runs locally, on port 8080
. To clone, build, test, and run the Voter service locally:
git clone --depth 1 --branch master \
https://github.com/jayaprakash9603/VotingSystem.git
The easiest way to get started with the Voter service API is to test the api's in the postman based on the HTTP method type.
The API entercandidate shall take a name as a parameter and save that into a table with a a count(vote count) initialized to 0.
Use local variables instead of a database to store the data.
The API castvote shall take a name as a parameter and increment the vote count and return it. It should enter vote only for a valid candidate.
The API countvote shall take a name as a parameter and should return the latest vote count. Validate candidate name.
The API listvote should return all names and votecounts. The return value is in JSON.
The API getwinner should return the name of the candidate who got the largest number of votes.
APIs shall be simultaneously executed by multi-users.
Implement unit testing
Example API usage
http://localhost:8080/entercandidate?name=ajay
http://localhost:8080/castvote?name=ajay
http://localhost:8080/countvote?name=ajay
http://localhost:8080/listvote
http://localhost:8080/getwinner
By default, the service runs on localhost
, port 8080
.
Purpose | Method | Endpoint |
---|---|---|
Enter Candidate | POST | /entercandidate |
Cast Vote | POST | /castvote |
Count Vote | POST | /countvote |
List Vote | GET | /listvote |
Get Winner | GET | /getwinner |
Submitting a new vote, requires an HTTP POST
request to the /votes
endpoint, and pass the candidate name as follows:
http POST http://localhost:8080/castvote?name=ajay
http http://localhost:8080/entercandidate
{
"message": "candidate added"
}
http http://localhost:8080/castvote
{
"candidates": [
"Chris Keniston",
"Darrell Castle",
"Donald Trump",
"Gary Johnson",
"Hillary Clinton",
"Jill Stein"
]
}
http http://localhost:8080/countvote
{
"results": [
{
"candidate": "Gary Johnson",
"votes": 20
},
{
"candidate": "Hillary Clinton",
"votes": 15
},
{
"candidate": "Donald Trump",
"votes": 11
},
{
"candidate": "Jill Stein",
"votes": 8
},
{
"candidate": "Chris Keniston",
"votes": 3
},
{
"candidate": "Darrell Castle",
"votes": 2
}
]
}
http http://localhost:8080/listvote
{
"kiran": 14,
"ajay": 20,
"sunil": 22,
"kishore": 34,
"kamal": 69
}
http http://localhost:8080/getwinner
{
"results": [
{
"candidate": "Gary Johnson",
"votes": 20
}
]
}