This repository demonstrates how to set up a RESTful API server using Dropwizard framework with Gradle build system.
- Java 17 or higher
- Gradle 8.5 or higher (included via Gradle wrapper)
dropwizard-with-gradle/
├── app/
│ ├── src/main/java/dev/vink/example/
│ │ ├── config/
│ │ │ └── AppConfig.java # Configuration class
│ │ ├── data/
│ │ │ ├── Person.java # Data model
│ │ │ └── PersonDatabase.java # In-memory database
│ │ ├── resources/
│ │ │ ├── HealthCheckService.java # Health check implementation
│ │ │ └── PersonService.java # REST endpoints
│ │ └── App.java # Application entry point
│ └── build.gradle # Project build configuration
├── config.yml # Server configuration
To build the application, run:
./gradlew clean buildThis will create two JAR files in app/build/libs/:
dropwizard-with-gradle-1.0.0.jar: The application JAR with dependencies for dropwizard serverapp-1.0.0.jar: The simple application JAR without dependencies
To start the server:
java -jar app/build/libs/dropwizard-with-gradle-1.0.0.jar server config.ymlThe server will start with configuration passed in config.yml:
- Application port: 8080
- Admin port: 8081
- GET
/person- List all persons - GET
/person/{id}- Get person by ID - POST
/person/add- Add a new person
Example POST request:
{
"firstName": "John",
"lastName": "Doe",
"email": "john.doe@example.com",
"id": 1
}- GET
/healthcheck- View application health status
The application is configured via config.yml. Key configuration options:
environment: development
apiVersion: v1
server:
applicationConnectors:
- type: http
port: 8080
adminConnectors:
- type: http
port: 8081
logging:
level: INFO
loggers:
dev.vink.example: DEBUG- Dropwizard 4.0.14
- Guava 33.0.0-jre
- JUnit Jupiter 5.10.2 (for testing)
The project uses the Shadow plugin to create a fat JAR. To build it:
./gradlew shadowJarThis project is licensed under the MIT License - see the LICENSE file for details.