le.com/bar").accept(MediaType.APPLICATION_JSON).body(body); ResponseEntity<MyResponse> response = template.exchange(request, MyResponse.class);
If you would like to provide a URI template with variables, consider using {@link org.springframework.web.util.UriTemplate}:
URI uri = new UriTemplate("http://example.com/{foo}"").expand("bar"); RequestEntity<MyRequest> request = RequestEntity.post(uri).accept(MediaType.APPLICATION_JSON).body(body);
Can also be used in Spring MVC, as a parameter in a @Controller method:
@RequestMapping("/handle") public void handle(RequestEntity<String> request) { HttpMethod method = request.getMethod(); URI url = request.getUrl(); String body = request.getBody(); }
@author Arjen Poutsma
@since 4.1
@see #getMethod()
@see #getUrl()