Top Description Inners Fields Constructors Methods
org.springframework.http

public Class RequestEntity<T>

extends HttpEntity<T>
Class Inheritance
Known Direct Subclasses
org.springframework.http.RequestEntity.UriTemplateRequestEntity
Type Parameters
<T>
the body type
Imports
java.lang.reflect.Type, java.net.URI, java.nio.charset.Charset, java.time.Instant, .ZonedDateTime, java.util.Arrays, .Map, java.util.function.Consumer, org.springframework.lang.Nullable, org.springframework.util.MultiValueMap, .ObjectUtils

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();
}
Authors
Arjen Poutsma, Sebastien Deleuze, Parviz Rozikov
Since
4.1
See Also
getMethod(), getUrl(), org.springframework.web.client.RestOperations#exchange(RequestEntity, Class), ResponseEntity

Nested and Inner Type Summary

Modifier and TypeClass 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.HeadersBuilder<B>
>

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 URI.

Field Summary

Modifier and TypeField and Description
private final HttpMethod
private final Type
private final URI
Inherited from org.springframework.http.HttpEntity:
EMPTY

Constructor Summary

AccessConstructor 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.

Method Summary

Modifier and TypeMethod and Description
public static RequestEntity.HeadersBuilder<?>

Returns:

the created builder
delete
(URI
the URL
url
)

Create an HTTP DELETE builder with the given url.

public static RequestEntity.HeadersBuilder<?>

Returns:

the created builder
delete
(String
the uri template to use
uriTemplate
,
Object...
variables to expand the URI template with
uriVariables
)

Create an HTTP DELETE builder with the given string base uri template.

public boolean
equals(Object
the reference object with which to compare.
other
)

Overrides org.springframework.http.HttpEntity.equals.

Indicates whether some other object is "equal to" this one.

pack-priv static <T> String
format(HttpMethod httpMethod, String url, T body, HttpHeaders headers)

public static RequestEntity.HeadersBuilder<?>

Returns:

the created builder
get
(URI
the URL
url
)

Create an HTTP GET builder with the given url.

public static RequestEntity.HeadersBuilder<?>

Returns:

the created builder
get
(String
the uri template to use
uriTemplate
,
Object...
variables to expand the URI template with
uriVariables
)

Create an HTTP GET builder with the given string base uri template.

public HttpMethod

Returns:

the HTTP method as an HttpMethod enum value
getMethod
()

Return the HTTP method of the request.

public Type

Returns:

the request's body type, or null if not known
getType
()

Return the type of the request's body.

public URI
getUrl()

Return the URI for the target HTTP endpoint.

public int
hashCode()

Overrides org.springframework.http.HttpEntity.hashCode.

Returns a hash code value for this object.

public static RequestEntity.HeadersBuilder<?>

Returns:

the created builder
head
(URI
the URL
url
)

Create an HTTP HEAD builder with the given url.

public static RequestEntity.HeadersBuilder<?>

Returns:

the created builder
head
(String
the uri template to use
uriTemplate
,
Object...
variables to expand the URI template with
uriVariables
)

Create an HTTP HEAD builder with the given string base uri template.

public static RequestEntity.BodyBuilder

Returns:

the created builder
method
(HttpMethod
the HTTP method (GET, POST, etc)
method
,
URI
the URL
url
)

Create a builder with the given method and url.

public static RequestEntity.BodyBuilder

Returns:

the created builder
method
(HttpMethod
the 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.BodyBuilder

Returns:

the created builder
method
(HttpMethod
the 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.HeadersBuilder<?>

Returns:

the created builder
options
(URI
the URL
url
)

Creates an HTTP OPTIONS builder with the given url.

public static RequestEntity.HeadersBuilder<?>

Returns:

the created builder
options
(String
the uri template to use
uriTemplate
,
Object...
variables to expand the URI template with
uriVariables
)

Creates an HTTP OPTIONS builder with the given string base uri template.

public static RequestEntity.BodyBuilder

Returns:

the created builder
patch
(URI
the URL
url
)

Create an HTTP PATCH builder with the given url.

public static RequestEntity.BodyBuilder

Returns:

the created builder
patch
(String
the uri template to use
uriTemplate
,
Object...
variables to expand the URI template with
uriVariables
)

Create an HTTP PATCH builder with the given string base uri template.

public static RequestEntity.BodyBuilder

Returns:

the created builder
post
(URI
the URL
url
)

Create an HTTP POST builder with the given url.

public static RequestEntity.BodyBuilder

Returns:

the created builder
post
(String
the uri template to use
uriTemplate
,
Object...
variables to expand the URI template with
uriVariables
)

Create an HTTP POST builder with the given string base uri template.

public static RequestEntity.BodyBuilder

Returns:

the created builder
put
(URI
the URL
url
)

Create an HTTP PUT builder with the given url.

public static RequestEntity.BodyBuilder

Returns:

the created builder
put
(String
the uri template to use
uriTemplate
,
Object...
variables to expand the URI template with
uriVariables
)

Create an HTTP PUT builder with the given string base uri template.

public String
toString()

Overrides org.springframework.http.HttpEntity.toString.

Returns a string representation of the object.

Inherited from org.springframework.http.HttpEntity:
getBodygetHeadershasBody