Issue
What's the difference between ResponseEntity
and HttpEntity
in Spring? I want to know the difference between the two and when to use them in a Spring MVC controller.
Solution
HttpEntity can be used to create both RequestEntity and ResponseEntity.
Where as ResponseEntity is subclassed from HttpEntity with a more elaborative way to send the ResponseObject and it only limited to sending the Response. Some Key differences are below :
ResponseEntity inherited from HttpEntity that has an additional HttpStatus Code while Sending the ResponseEntity Object.
Also it has ResponseEntity.BodyBuilder which adds body to the response Object and ResponseEntity.HeadersBuilder which adds header to the Response object.
Answered By - Akash Roy