To create an API to print Hello World
- Create a spring boot project using Spring Initilzr.
- Add required dependencies.
- Choose the configuration file type i.e, either Gradle or Maven.
- Add a method called hello in the Application.java program
- Run the project.
- View the result at http://localhost:8080/
java
package com.project.javafullstack.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class Controller {
@GetMapping("/hello")
public String hello(){
return "Hello World";
}
}
Hence, an API to print Hello World is created and executed successfully