70 points
7 3 1

REST APIs / Services with Spring boot

First create a project with spring starter from here :- , Fill the form and select dependencies from add dependencies button. Select lombok, Spring Data JPA, H2 Database.
Then Generate a project and open it in your IDE.
Now we will need below things minimum to develop REST API :
Controller – Which will serve to HTTP end points.
Service – Which will be used for defining our business logic.
Repository – Which will be used for communicating with DB with our POJO structure.
Model – Which will be our model which directly communicate to DB and HTTP call.
Now let’s first make Our Model ---
public class UserDTO {

private Long id;

private String name;

private String mobile;

private String address;

private Integer age;



Now let’s make Repository layer ---
public interface HomeRepository extends JpaRepository<UserDTO,Long>{


Now We will need to make our service which will used to get users.


public class HomeService{


private HomeRepository homeRepo;

public List<UserDTO> getAll() {

return homeRepo.findAll();




Create a controller like this and import inbuilt classes …...



public class HomeController{

private HomeService homeService;

public List<UserDTO> getUsers(){
return homeService.getAll();




Now we will need to configure  H2 properties in proprty file ---



Now in post man hit api with http://localhost:8080/getUser  this will get All users  in database. In nnext blog we will see full CRUD with Spring boot.

You can also visit other Spring boot blogs of mine from below links :- 

Bean Life cycle –

Various Annotations –

Postgre CRUD –


I&rsquo;m so happy to meet this blog that makes me understand a lot. After I read it again and again, I understand many lessons in this blog.
Thank you. A thousand thousand blessings to you for sharing knowledge.

More Posts

Create a Web application in Spring boot with PostgreSQL (Part-3) darshan1507 - May 25
Spring framework annotations @Autowire @Component @Bean @Configuration @Value darshan1507 - Jun 5
Uploading files to AWS S3 Bucket using Spring Boot darshan1507 - Jun 7
Application Properties in Spring Boot thistimeonly32 - Apr 4
Spring AOP Interview Questions Lalit Kumar - Dec 30, 2020
web server failed to start. port 8080 was already in use. SharadMagar450 - Aug 31
Create a Web application in Spring boot with PostgreSQL (Part-2) darshan1507 - May 25
Create a Web application in Spring boot with PostgreSQL (Part-1) darshan1507 - May 25
4 reasons why you should use GraphQL over REST APIs blessinghirwa - Aug 8
How call REST Services in Android Application darshan1507 - Jun 7