How to Create a REST API With Spring Boot

In previous post we have learn how to change port of server . If you new one then follow spring boot tutorial example here .  In this tutorial we will learn restful web services  with spring boot . rest services is very important topic for java developers . If you are new then first read how to create spring boot application  . Now are we going to restful web services example in java with spring boot.

Firstly we will create controller , it is endpoint of our rest api’s.


import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;


public class HelloController {

	public User getApplicationName(){
		User user = new User( 10L, "shivam");
		return user;

Now we will create model class user


public class User {
	private Long userId;
	private String name;
	public User(){
	public User(Long userId, String name) {
		this.userId = userId; = name;

   public Long getUserId() {
		return userId;

	public String getName() {
		return name;



Now run your spring boot application and hit url http://localhost:8080/user . then you will  got



You can this spring boot example below.

   Download Rest Application

Leave a Reply

Your email address will not be published. Required fields are marked *

+ 80 = 86