Would someone please describe to me what exactly an HTTP entity is?
I am reading the HTTPClient documentation, but I do not really understand what t
HttpEntity
is what you are going to pass in Request(with header) and what you are getting in Response.
For Get Request we are passing simple String
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
HttpEntity entity = new HttpEntity(headers);
For Post We are going to pass complete Entity Class
public String createProducts(@RequestBody Product product) {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
HttpEntity entity = new HttpEntity(product,headers);
return restTemplate.exchange(
"http://localhost:8080/products", HttpMethod.POST, entity, String.class
).getBody();
}