Build Java Rest API
Build Java Rest API
Let’s not complicate things and create a simple todo API where you get a list of
tasks with Get request and create a task with the post request. since we are
focussing on the Java REST API, let’s go with the simple API.
Prerequisites
Example Project
Start With Spring Initializer
Configure H2 Database
Understanding Project Structure
Auto Restart and Live Reload With Spring Dev Tools
Production-Ready Features With Spring Actuator
Create Repository With Spring Data Rest
Controller, Spring HATEOAS and Exception Handling
Testing the URLs With Postman
Unit Testing With JUnit 5
Integration Testing With Rest Assured
Code Coverage
Swagger Documentation
Dockerize The API
Best Practices
Conclusion
Prerequisites
Here are the prerequisites for this article. If you don’t have these on your system
go ahead and install them if you want to practice on your machine.
Java
Eclipse IDE
Spring Boot
H2 Database
JUnit 5
Maven
JMeter
Project Lombok
Postman
Java Runtime and SDK: We need java runtime and SDK for the Java applications to
run. This is the core component for running Java applications.
Eclipse IDE: We need an IDE to develop this application. There are other IDEs such
as NetBeans, IntelliJ IDE, etc. Eclipse is an open-source IDE and has very good
community support.
Spring Boot: Spring is a framework that makes our life easy to develop these java
based applications. Spring Boot makes it easy to create stand-alone, production-
grade Spring based Applications that you can “just run”.
H2 Database: H2 Database is a very fast, open-source, JDBC API, and in-memory
database. We use this as a database for our project.
Maven: We need Maven to install dependencies, package, and build the project.
JMeter: It’s open-source software that is designed for load testing functional
behavior and measures the performance of the application.
Project Lombok: This is a java library that automatically plugs into your editor
and builds tools, spicing up your java. You would never write another getter or
equals method again, with one annotation your class has a fully-featured builder,
Automate your logging variables, and much more.