HttpEntity that also exposes the HTTP method and the
target URL. For use in the RestTemplate to prepare requests with
and in @Controller methods to represent request input.
Example use with the RestTemplate:
MyRequest body = ...
RequestEntity<MyRequest> request = RequestEntity
.post("https://example.com/{foo}", "bar")
.accept(MediaType.APPLICATION_JSON)
.body(body);
ResponseEntity<MyResponse> response = template.exchange(request, MyResponse.class);
Example use in an @Controller:
@RequestMapping("/handle")
public void handle(RequestEntity<String> request) {
HttpMethod method = request.getMethod();
URI url = request.getUrl();
String body = request.getBody();
}
getMethod(), getUrl(), org.springframework.web.client.RestOperations#exchange(RequestEntity, Class) , ResponseEntity
| Modifier and Type | Class and Description |
|---|---|
| public static interface | RequestEntity.BodyBuilder
Defines a builder that adds a body to the response entity. |
| private static class | |
| public static interface | RequestEntity.HeadersBuilder<
the builder subclass B extends RequestEntity.Defines a builder that adds headers to the request entity. |
| public static class | RequestEntity.UriTemplateRequestEntity<
the body type T>RequestEntity initialized with a URI template and variables instead of a |
| Modifier and Type | Field and Description |
|---|---|
| private final HttpMethod | |
| private final Type | |
| private final URI |
| Access | Constructor and Description |
|---|---|
| public | RequestEntity(HttpMethod
the method method, URI the URL url)Constructor with method and URL but without body nor headers. |
| public | RequestEntity(T
the body body, HttpMethod the method method, URI the URL url)Constructor with method, URL and body but without headers. |
| public | RequestEntity(T
the body body, HttpMethod the method method, URI the URL url, Type the type used for generic type resolution type)Constructor with method, URL, body and type but without headers. |
| public | RequestEntity(MultiValueMap<String, String>
the headers headers, HttpMethod the method method, URI the URL url)Constructor with method, URL and headers but without body. |
| public | RequestEntity(T
the body body, MultiValueMap<String, String> the headers headers, HttpMethod the method method, URI the URL url)Constructor with method, URL, headers and body. |
| public | RequestEntity(T
the body body, MultiValueMap<String, String> the headers headers, HttpMethod the method method, URI the URL url, Type the type used for generic type resolution type)Constructor with method, URL, headers, body and type. |
| Modifier and Type | Method and Description |
|---|---|
| public static RequestEntity. | |
| public static RequestEntity. | |
| public boolean | equals(Object
the reference object with which to compare. other)Overrides org. |
| pack-priv static <T> String | |
| public static RequestEntity. | |
| public static RequestEntity. | |
| public HttpMethod | Returns: the HTTP method as anHttpMethod enum valueReturn the HTTP method of the request. |
| public Type | Returns: the request's body type, ornull if not knownReturn the type of the request's body. |
| public URI | |
| public int | hashCode()
Overrides org. |
| public static RequestEntity. | |
| public static RequestEntity. | |
| public static RequestEntity. | Returns: the created builderthe HTTP method (GET, POST, etc) method, URI the URL url)Create a builder with the given method and url. |
| public static RequestEntity. | Returns: the created builderthe HTTP method (GET, POST, etc) method, String the uri template to use uriTemplate, Object... variables to expand the URI template with uriVariables)Create a builder with the given HTTP method, URI template, and variables. |
| public static RequestEntity. | Returns: the created builderthe HTTP method (GET, POST, etc) method, String the uri template to use uriTemplate, Map<String, ?> uriVariables)Create a builder with the given HTTP method, URI template, and variables. |
| public static RequestEntity. | |
| public static RequestEntity. | |
| public static RequestEntity. | |
| public static RequestEntity. | |
| public static RequestEntity. | |
| public static RequestEntity. | |
| public static RequestEntity. | |
| public static RequestEntity. | |
| public String | toString()
Overrides org. |