Skip to content

The Voter Spring Boot RESTful Web Service, backed by MongoDB, and uses RabbitMQ for IPC

License

Notifications You must be signed in to change notification settings

DotedLabs/voter-service

 
 

Repository files navigation

Build Status Dependencies Layers Version

Voter Service

Introduction

The Voter Spring Boot Service is a RESTful Web Service, backed by MongoDB, using Atlas on GCP, and RabbitMQ, using CloudAMQP on GCP. It is part of the Voter API (see diagram below). The Voter service exposes several HTTP API endpoints, listed below. API users can review a list candidates, submit a vote, view voting results, and inspect technical information about the running service.

Architecture

Voter Service Endpoints

The service uses a context path of /voter. All endpoints must be are prefixed with this sub-path.

Purpose Method Endpoint
List All Service Endpoints GET /voter/mappings
Create Vote POST /voter/voters
Read Vote GET /voter/voters/{id}
Read Votes GET /voter/voters
Update Vote PUT /voter/voters/{id}
Delete Vote DELETE /voter/voters/{id}
List Candidates GET /voter/candidates/{election}
View Voting Results GET /voter/results/{election}
View Total Votes GET /voter/results/{election}/votes
View Winner(s) GET /voter/winners/{election}
View Winning Vote Count GET /voter/winners/{election}/votes
Drop All Candidates POST /voter/drop/candidates
Drop All Votes POST /voter/drop/votes
Service Info GET /voter/info
Service Health GET /voter/health
Other Spring Actuator endpoints GET voter/actuator, voter/metrics, voter/env, voter/configprops, etc.
Other HATEOAS endpoints for /voter/votes Various page sort, size, etc.

The HAL Browser API browser for the hal+json media type is installed alongside the service. It can be accessed at http://localhost:8099/voter/actuator/.

Voting

Submitting a new candidate requires an HTTP POST request to the /voter/votes endpoint, as follows:

HTTPie

http POST http://localhost:8099/voter/votes \
  candidate="Jill Stein" \
  election="2016 Presidential Election"

cURL

curl -X POST \
  -H "Content-Type: application/json" \
  -d '{ "candidate": "Jill Stein", "election": "2016 Presidential Election" }' \
  "http://localhost:8099/voter/votes"

wget

wget --method POST \
  --header 'content-type: application/json' \
  --body-data '{ "candidate": "Jill Stein", "election": "2016 Presidential Election" }' \
  --no-verbose \
  --output-document - http://localhost:8099/voter/votes

Sample Output

API users can also create random voting data by calling the /voter/simulation endpoint. Using HTTPie command line HTTP client.

http http://localhost:8099/voter/simulation/2016%20Presidential%20Election
{
    "message": "Simulation data created!"
}
http http://localhost:8099/voter/candidates/db/2016%20Presidential%20Election
{
    "candidates": [
        {
            "election": "2016 Presidential Election",
            "fullName": "Darrell Castle",
            "politicalParty": "Constitution Party"
        },
        {
            "election": "2016 Presidential Election",
            "fullName": "Hillary Clinton",
            "politicalParty": "Democratic Party"
        },
        {
            "election": "2016 Presidential Election",
            "fullName": "Gary Johnson",
            "politicalParty": "Libertarian Party"
        }
    ]
}
http http://localhost:8099/voter/results/2016%20Presidential%20Election
{
    "results": [
        {
            "candidate": "Darrell Castle",
            "votes": 19
        },
        {
            "candidate": "Donald Trump",
            "votes": 15
        },
        {
            "candidate": "Gary Johnson",
            "votes": 15
        },
        {
            "candidate": "Jill Stein",
            "votes": 13
        }
    ]
}
http http://localhost:8099/voter/results/2016%20Presidential%20Election/votes
{
    "votes": 80
}
http http://localhost:8099/voter/winners/2016%20Presidential%20Election
{
    "results": [
        {
            "candidate": "Darrell Castle",
            "votes": 19
        }
    ]
}
http http://localhost:8099/voter/winners/2016%20Presidential%20Election/votes
{
    "votes": 19
}
http POST http://localhost:8099/voter/votes \
    candidate="Jill Stein" \
    election="2016 Presidential Election"
{
    "_links": {
        "self": {
            "href": "http://localhost:8099/voter/votes/590548541b8ebf700f9c2a62"
        },
        "candidate": {
            "href": "http://localhost:8099/voter/votes/590548541b8ebf700f9c2a62"
        }
    },
    "candidate": "Jill Stein",
    "election": "2016 Presidential Election"
}

About

The Voter Spring Boot RESTful Web Service, backed by MongoDB, and uses RabbitMQ for IPC

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 91.9%
  • Shell 6.5%
  • Dockerfile 1.6%