Package org.springframework.http
Class RequestEntity<T>
java.lang.Object
org.springframework.http.HttpEntity<T>
org.springframework.http.RequestEntity<T>
- Type Parameters:
- T- the body type
- Direct Known Subclasses:
- RequestEntity.UriTemplateRequestEntity
Extension of 
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();
 }
 - Since:
- 4.1
- Author:
- Arjen Poutsma, Sebastien Deleuze, Parviz Rozikov
- See Also:
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic interfaceDefines a builder that adds a body to the response entity.static interfaceDefines a builder that adds headers to the request entity.static classRequestEntity initialized with a URI template and variables instead of aURI.
- 
Field SummaryFields inherited from class org.springframework.http.HttpEntityEMPTY
- 
Constructor SummaryConstructorsConstructorDescriptionRequestEntity(HttpMethod method, URI url) Constructor with method and URL but without body nor headers.RequestEntity(MultiValueMap<String, String> headers, HttpMethod method, URI url) Constructor with method, URL and headers but without body.RequestEntity(T body, HttpMethod method, URI url) Constructor with method, URL and body but without headers.RequestEntity(T body, HttpMethod method, URI url, Type type) Constructor with method, URL, body and type but without headers.RequestEntity(T body, MultiValueMap<String, String> headers, HttpMethod method, URI url) Constructor with method, URL, headers and body.RequestEntity(T body, MultiValueMap<String, String> headers, HttpMethod method, URI url, Type type) Constructor with method, URL, headers, body and type.
- 
Method SummaryModifier and TypeMethodDescriptionstatic RequestEntity.HeadersBuilder<?>Create an HTTP DELETE builder with the given string base uri template.static RequestEntity.HeadersBuilder<?>Create an HTTP DELETE builder with the given url.booleanstatic RequestEntity.HeadersBuilder<?>Create an HTTP GET builder with the given string base uri template.static RequestEntity.HeadersBuilder<?>Create an HTTP GET builder with the given url.Return the HTTP method of the request.getType()Return the type of the request's body.getUrl()Return theURIfor the target HTTP endpoint.inthashCode()static RequestEntity.HeadersBuilder<?>Create an HTTP HEAD builder with the given string base uri template.static RequestEntity.HeadersBuilder<?>Create an HTTP HEAD builder with the given url.static RequestEntity.BodyBuildermethod(HttpMethod method, String uriTemplate, Object... uriVariables) Create a builder with the given HTTP method, URI template, and variables.static RequestEntity.BodyBuildermethod(HttpMethod method, String uriTemplate, Map<String, ?> uriVariables) Create a builder with the given HTTP method, URI template, and variables.static RequestEntity.BodyBuildermethod(HttpMethod method, URI url) Create a builder with the given method and url.static RequestEntity.HeadersBuilder<?>Creates an HTTP OPTIONS builder with the given string base uri template.static RequestEntity.HeadersBuilder<?>Creates an HTTP OPTIONS builder with the given url.static RequestEntity.BodyBuilderCreate an HTTP PATCH builder with the given string base uri template.static RequestEntity.BodyBuilderCreate an HTTP PATCH builder with the given url.static RequestEntity.BodyBuilderCreate an HTTP POST builder with the given string base uri template.static RequestEntity.BodyBuilderCreate an HTTP POST builder with the given url.static RequestEntity.BodyBuilderCreate an HTTP PUT builder with the given string base uri template.static RequestEntity.BodyBuilderCreate an HTTP PUT builder with the given url.toString()Methods inherited from class org.springframework.http.HttpEntitygetBody, getHeaders, hasBody
- 
Constructor Details- 
RequestEntityConstructor with method and URL but without body nor headers.- Parameters:
- method- the method
- url- the URL
 
- 
RequestEntityConstructor with method, URL and body but without headers.- Parameters:
- body- the body
- method- the method
- url- the URL
 
- 
RequestEntityConstructor with method, URL, body and type but without headers.- Parameters:
- body- the body
- method- the method
- url- the URL
- type- the type used for generic type resolution
- Since:
- 4.3
 
- 
RequestEntityConstructor with method, URL and headers but without body.- Parameters:
- headers- the headers
- method- the method
- url- the URL
 
- 
RequestEntitypublic RequestEntity(@Nullable T body, @Nullable MultiValueMap<String, String> headers, @Nullable HttpMethod method, URI url) Constructor with method, URL, headers and body.- Parameters:
- body- the body
- headers- the headers
- method- the method
- url- the URL
 
- 
RequestEntitypublic RequestEntity(@Nullable T body, @Nullable MultiValueMap<String, String> headers, @Nullable HttpMethod method, @Nullable URI url, @Nullable Type type) Constructor with method, URL, headers, body and type.- Parameters:
- body- the body
- headers- the headers
- method- the method
- url- the URL
- type- the type used for generic type resolution
- Since:
- 4.3
 
 
- 
- 
Method Details- 
getMethodReturn the HTTP method of the request.- Returns:
- the HTTP method as an HttpMethodenum value
 
- 
getUrlReturn theURIfor the target HTTP endpoint.Note: This method raises UnsupportedOperationExceptionif theRequestEntitywas created with a URI template and variables rather than with aURIinstance. This is because a URI cannot be created without further input on how to expand template and encode the URI. In such cases, theURIis prepared by theRestTemplatewith the help of theUriTemplateHandlerit is configured with.
- 
getTypeReturn the type of the request's body.- Returns:
- the request's body type, or nullif not known
- Since:
- 4.3
 
- 
equals- Overrides:
- equalsin class- HttpEntity<T>
 
- 
hashCodepublic int hashCode()- Overrides:
- hashCodein class- HttpEntity<T>
 
- 
toString- Overrides:
- toStringin class- HttpEntity<T>
 
- 
methodCreate a builder with the given method and url.- Parameters:
- method- the HTTP method (GET, POST, etc)
- url- the URL
- Returns:
- the created builder
 
- 
methodpublic static RequestEntity.BodyBuilder method(HttpMethod method, String uriTemplate, Object... uriVariables) Create a builder with the given HTTP method, URI template, and variables.- Parameters:
- method- the HTTP method (GET, POST, etc)
- uriTemplate- the uri template to use
- uriVariables- variables to expand the URI template with
- Returns:
- the created builder
- Since:
- 5.3
 
- 
methodpublic static RequestEntity.BodyBuilder method(HttpMethod method, String uriTemplate, Map<String, ?> uriVariables) Create a builder with the given HTTP method, URI template, and variables.- Parameters:
- method- the HTTP method (GET, POST, etc)
- uriTemplate- the uri template to use
- Returns:
- the created builder
- Since:
- 5.3
 
- 
getCreate an HTTP GET builder with the given url.- Parameters:
- url- the URL
- Returns:
- the created builder
 
- 
getCreate an HTTP GET builder with the given string base uri template.- Parameters:
- uriTemplate- the uri template to use
- uriVariables- variables to expand the URI template with
- Returns:
- the created builder
- Since:
- 5.3
 
- 
headCreate an HTTP HEAD builder with the given url.- Parameters:
- url- the URL
- Returns:
- the created builder
 
- 
headCreate an HTTP HEAD builder with the given string base uri template.- Parameters:
- uriTemplate- the uri template to use
- uriVariables- variables to expand the URI template with
- Returns:
- the created builder
- Since:
- 5.3
 
- 
postCreate an HTTP POST builder with the given url.- Parameters:
- url- the URL
- Returns:
- the created builder
 
- 
postCreate an HTTP POST builder with the given string base uri template.- Parameters:
- uriTemplate- the uri template to use
- uriVariables- variables to expand the URI template with
- Returns:
- the created builder
- Since:
- 5.3
 
- 
putCreate an HTTP PUT builder with the given url.- Parameters:
- url- the URL
- Returns:
- the created builder
 
- 
putCreate an HTTP PUT builder with the given string base uri template.- Parameters:
- uriTemplate- the uri template to use
- uriVariables- variables to expand the URI template with
- Returns:
- the created builder
- Since:
- 5.3
 
- 
patchCreate an HTTP PATCH builder with the given url.- Parameters:
- url- the URL
- Returns:
- the created builder
 
- 
patchCreate an HTTP PATCH builder with the given string base uri template.- Parameters:
- uriTemplate- the uri template to use
- uriVariables- variables to expand the URI template with
- Returns:
- the created builder
- Since:
- 5.3
 
- 
deleteCreate an HTTP DELETE builder with the given url.- Parameters:
- url- the URL
- Returns:
- the created builder
 
- 
deleteCreate an HTTP DELETE builder with the given string base uri template.- Parameters:
- uriTemplate- the uri template to use
- uriVariables- variables to expand the URI template with
- Returns:
- the created builder
- Since:
- 5.3
 
- 
optionsCreates an HTTP OPTIONS builder with the given url.- Parameters:
- url- the URL
- Returns:
- the created builder
 
- 
optionsCreates an HTTP OPTIONS builder with the given string base uri template.- Parameters:
- uriTemplate- the uri template to use
- uriVariables- variables to expand the URI template with
- Returns:
- the created builder
- Since:
- 5.3
 
 
-