An HTTP response header carries metadata from the server separately from the response payload body. Use headers when the client needs response details beyond the returned resource. section 7.3.1
With Spring's RestTemplate, getForObject() returns the payload directly. Choose getForEntity() when the client also needs the response headers; the returned ResponseEntity wraps the payload and exposes those details. section 7.3.1
Reading the Date header
Fetch an ingredient with getForEntity(), inspect responseEntity.getHeaders().getDate(), and then obtain the resource through responseEntity.getBody().
public Ingredient getIngredientById(String ingredientId) {
ResponseEntity<Ingredient> responseEntity =
rest.getForEntity("http://localhost:8080/ingredients/{id}",
Ingredient.class, ingredientId);
log.info("Fetched time: {}",
responseEntity.getHeaders().getDate());
return responseEntity.getBody();
}
See the complete RestTemplate example that retrieves a resource, reads its response headers, and returns the payload body. section 7.3.1



