Skip to content

Latest commit

 

History

History
38 lines (29 loc) · 1.1 KB

File metadata and controls

38 lines (29 loc) · 1.1 KB

Simple Java Spring boot web server

hello world in spring on the root path

Using curl to preview the response:

❯ curl localhost:8080/hello\?name=LearnAWS.io
Hello LearnAWS.io! It's 2024-06-19T22:18:38.787292626Z%   

How to run this?

Start the spring web server using mvn

mvn spring-boot:run

Code for GET routes

@GetMapping("/")
public ResponseEntity<String> welcome() {
  String body = """
      <h1>Welcome to Spring boot</h1>
      <p>Made by <a href='https://learnaws.io'>LearnAWS.io</a>
      """;
  return ResponseEntity.ok().header("Content-Type", "text/html").body(body);
}

@GetMapping("/hello")
public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
  return String.format("Hello %s! It's %s", name, Instant.now());
}