What Is ResponseEntity in Spring Boot? How to Use It, Return Status Codes and Headers, and How It Differs from @ResponseStatus
Learn what ResponseEntity is in Spring Boot through its three parts: status, headers, and body. Code examples cover the builder API (ok(), created(URI), noContent(), notFound(), status()), how to set Location, Cache-Control, ETag, and Content-Disposition headers, and how to use the Void type for responses without a body and combine ResponseEntity with Optional. Decision tables show when to return domain objects directly and when to use @ResponseStatus instead. Common pitfalls, like a 201 response with an empty body or headers that never reach the client, are reproduced with curl and MockMvc and then fixed (Spring Boot 3.x).