Spring Boot - Create a Simple RESTful Web Service
Mohamad's interest is in Programming (Mobile, Web, Database and Machine Learning). He is studying at the Center For Artificial Intelligence Technology (CAIT), Universiti Kebangsaan Malaysia (UKM).
Objective: Implement a basic REST controller that returns a greeting message.
Steps:
Create a REST Controller:
- Add a new class annotated with
@RestController.
- Add a new class annotated with
package com.example.demo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class GreetingController {
@GetMapping("/greeting")
public String greeting() {
return "Hello, World!";
}
}
Test the Endpoint:
- Run the application and navigate to
http://localhost:8080/greetingto see the greeting message.
- Run the application and navigate to