What is Drop-wizard
Drop wizard is simply All the listed libraries in one package.
- metrics
- jetty
- jersey
- jackson
- jdbi
- hibernate
- logback
- mustache
- freemarker
1 2 | mvn archetype:generate -DgroupId=dec.mchoice.tech.talk -DartifactId=Sample-dw-app -Dname=SampleApplication -Dpackage=dev.mchoice.tech.talk dev.innova.drp -DarchetypeGroupId=io.dropwizard.archetypes -DarchetypeArtifactId=java-simple -DinteractiveMode=false |
After creating project it will create this kind of project structure.
Biggest advantage of use maven archetype no need to configure any dependencies or plugin in POM.xml file and it will generate executable jar file . Next step is create Rest API end point.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | @Path("/student") public class StudentManagement { @POST @Timed @Path("/save") @Produces(MediaType.APPLICATION_JSON) @Consumes({MediaType.APPLICATION_JSON}) public Response addPerson(Student student) { Map<String, Object> response = new HashMap<>(); response.put("statusCode", "S1000"); response.put("description", "Successfully added Student"); return Response.ok(response).build(); } } |
1 2 3 4 5 6 7 8 | @Override public void run(final SampleApplicationConfiguration configuration, final Environment environment) { environment.jersey().register(new StudentManagement()); } |
1 | java -jar Sample-dw-app-1.0-SNAPSHOT.jar server |
After running it will start in 8080 port(application port) and there is another port 8081 (Admin port ).
Next tutorial we will discuss how to change the default configurations and what are the usages of admin port.
Then you can use curl request or postmen to send request and check the Rest API.