Skip to content
No description, website, or topics provided.
Java
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.gitignore
.travis.yml
README.md
build.gradle
gradlew
gradlew.bat
new_user.json
server.yml
settings.gradle
unique_user.json

README.md

Build Status

CRUDUsers

Sample built on https://www.dropwizard.io/ and tested on JDK 12 and Gradle 5.2.1. Users deserialized from server.yml and maintained in memory.

  • UserResource allows clients to create, read, update, delete or list users.
  • A list of maps is used to track users by their ids.
  • Structured logging has been configured for the console.
  • Routes are @Timed using Dropwizard codahale metric annotations.
  • Write unit tests for the service.
  • A code coverage report is generated by Jacoco at build/reports/jacoco/test/html/index.html.
  • The user JSON includes id, first name, last name, zip code, and email address and is immutable.

Building

./gradlew build

Starting

java -jar build/libs/CRUDUsers-1.0-all.jar server server.yml

Testing

Unit

./gradlew test jacocoTestReport

API

List

$ curl localhost:8080/users 2>/dev/null | jq .
[
  {
    "id": 1,
    "first": "Billy",
    "last": "Fisher",
    "zip": "97078",
    "email": "billyjfisher@gmail.com"
  },
  {
    "id": 2,
    "first": "Stacey",
    "last": "Wright",
    "zip": "11029",
    "email": "stacey.is.wright@gmail.com"
  }
]

Create

$ curl --request POST --header 'Content-Type: application/json' --data "$(cat unique_user.json)" -i 2>/dev/null localhost:8080/users | head -n 1
HTTP/1.1 200 OK
$ curl --request POST --header 'Content-Type: application/json' --data "$(cat unique_user.json)" -i 2>/dev/null localhost:8080/users | head -n 1
HTTP/1.1 409 Conflict

Read

$ curl localhost:8080/users/1 2>/dev/null | jq .
{
  "id": 1,
  "first": "Billy",
  "last": "Fisher",
  "zip": "97078",
  "email": "billyjfisher@gmail.com"
}

$ curl localhost:8080/users/3 -i 2>/dev/null | head -n 1
HTTP/1.1 404 Not Found

Update

$ curl localhost:8080/users/2 2>/dev/null | jq .
{
  "id": 2,
  "first": "Stacey",
  "last": "Wright",
  "zip": "11029",
  "email": "stacey.is.wright@gmail.com"
}

$ curl --request PUT --header 'Content-Type: application/json' --data "$(cat new_user.json)" localhost:8080/users/2 -i 2>/dev/null | head -n 1
HTTP/1.1 409 Conflict

$ curl --request PUT --header 'Content-Type: application/json' --data "$(cat unique_user.json)" localhost:8080/users/2 -i 2>/dev/null | head -n 1
HTTP/1.1 204 No Content

$ curl localhost:8080/users/2 2>/dev/null | jq .
{
  "id": 2,
  "first": "Stefani",
  "last": "Germanotta",
  "zip": "97221",
  "email": "stefani.germanotta@someprovider.com"
}

Delete

$ curl --request DELETE localhost:8080/users/2 -i 2>/dev/null | head -n 1
HTTP/1.1 204 No Content

$ curl --request DELETE localhost:8080/users/2 -i 2>/dev/null | head -n 1
HTTP/1.1 404 Not Found

Health

$ curl http://localhost:8081/healthcheck 2>/dev/null | jq .
{
  "deadlocks": {
    "healthy": true,
    "duration": 0,
    "timestamp": "2019-12-26T16:05:22.852-08:00"
  },
  "dependency1": {
    "healthy": true,
    "duration": 0,
    "timestamp": "2019-12-26T16:05:22.852-08:00"
  }
}
You can’t perform that action at this time.