Spring Framework FAQ: Top Questions
30. What is ResponseEntity in Spring MVC?
ResponseEntity
is a wrapper for HTTP response including status code, headers, and body. It provides full control over the HTTP response.
📥 Example:
@GetMapping("/status")
public ResponseEntity<String> getStatus() {
return ResponseEntity.status(HttpStatus.OK).body("Everything is fine");
}
🏆 Expected Output:
Returns 200 OK with custom message.
🛠️ Use Cases:
- Customizing response status and headers.
- Standardizing API responses across services.