Bird
0
0

Given this REST controller method:

medium📝 component behavior Q4 of 15
Spring Boot - REST Controllers
Given this REST controller method:
@RestController
public class MyController {
  @GetMapping("/greet")
  public String greet() {
    return "Hello World";
  }
}

What will be the HTTP response body when accessing /greet?
A{"message":"Hello World"}
BError 404 Not Found
C<html>Hello World</html>
DHello World
Step-by-Step Solution
Solution:
  1. Step 1: Understand the return type and annotation

    The method returns a plain String and is inside a @RestController, so Spring Boot sends the string as the HTTP response body directly.
  2. Step 2: Check other options

    {"message":"Hello World"} is JSON format which requires an object, C is HTML which is not returned here, and D is an error which does not apply.
  3. Final Answer:

    Hello World -> Option D
  4. Quick Check:

    String return in @RestController = plain text response [OK]
Quick Trick: String return sends plain text in @RestController [OK]
Common Mistakes:
  • Expecting JSON without returning an object
  • Assuming HTML is returned automatically
  • Thinking 404 error occurs without reason

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes