Returning ResponseEntity from a REST controller gives explicit control over the HTTP status code, headers, and body, while returning a plain object lets Spring Boot handle those details automatically with a default 200 OK response.
A POST endpoint that creates a resource typically returns ResponseEntity.status(HttpStatus.CREATED).body(resource) so clients get a 201 with a Location header, whereas a simple GET endpoint can just return the resource object directly.
@PostMapping("/orders")
public ResponseEntity<Order> createOrder(@RequestBody OrderDto dto) {
Order created = orderService.create(dto);
return ResponseEntity.status(HttpStatus.CREATED).body(created);
}
@GetMapping("/orders/{id}")
public Order getOrder(@PathVariable Long id) {
return orderService.findById(id);
}A concise interview answer is
I return ResponseEntity when I need to control the status code or headers explicitly, like a 201 with a Location header on creation. For straightforward 200 OK responses where no customization is needed, returning the object directly is simpler and Spring wraps it automatically.
Last updated: 16 July 2026
Previous question: How do you configure and connect multiple databases in a Spring Boot application?