T
- the body typepublic class RequestEntity<T> extends HttpEntity<T>
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()
,
RestOperations.exchange(RequestEntity, Class)
,
ResponseEntity
Modifier and Type | Class and Description |
---|---|
static interface |
RequestEntity.BodyBuilder
Defines a builder that adds a body to the response entity.
|
static interface |
RequestEntity.HeadersBuilder<B extends RequestEntity.HeadersBuilder<B>>
Defines a builder that adds headers to the request entity.
|
static class |
RequestEntity.UriTemplateRequestEntity<T>
RequestEntity initialized with a URI template and variables instead of a
URI . |
EMPTY
Constructor and Description |
---|
RequestEntity(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.
|
Modifier and Type | Method and Description |
---|---|
static RequestEntity.HeadersBuilder<?> |
delete(String uriTemplate,
Object... uriVariables)
Create an HTTP DELETE builder with the given string base uri template.
|
static RequestEntity.HeadersBuilder<?> |
delete(URI url)
Create an HTTP DELETE builder with the given url.
|
boolean |
equals(Object other) |
static RequestEntity.HeadersBuilder<?> |
get(String uriTemplate,
Object... uriVariables)
Create an HTTP GET builder with the given string base uri template.
|
static RequestEntity.HeadersBuilder<?> |
get(URI url)
Create an HTTP GET builder with the given url.
|
HttpMethod |
getMethod()
Return the HTTP method of the request.
|
Type |
getType()
Return the type of the request's body.
|
URI |
getUrl()
Return the URL of the request.
|
int |
hashCode() |
static RequestEntity.HeadersBuilder<?> |
head(String uriTemplate,
Object... uriVariables)
Create an HTTP HEAD builder with the given string base uri template.
|
static RequestEntity.HeadersBuilder<?> |
head(URI url)
Create an HTTP HEAD builder with the given url.
|
static RequestEntity.BodyBuilder |
method(HttpMethod method,
String uriTemplate,
Map<String,?> uriVariables)
Create a builder with the given HTTP method, URI template, and variables.
|
static RequestEntity.BodyBuilder |
method(HttpMethod method,
String uriTemplate,
Object... uriVariables)
Create a builder with the given HTTP method, URI template, and variables.
|
static RequestEntity.BodyBuilder |
method(HttpMethod method,
URI url)
Create a builder with the given method and url.
|
static RequestEntity.HeadersBuilder<?> |
options(String uriTemplate,
Object... uriVariables)
Creates an HTTP OPTIONS builder with the given string base uri template.
|
static RequestEntity.HeadersBuilder<?> |
options(URI url)
Creates an HTTP OPTIONS builder with the given url.
|
static RequestEntity.BodyBuilder |
patch(String uriTemplate,
Object... uriVariables)
Create an HTTP PATCH builder with the given string base uri template.
|
static RequestEntity.BodyBuilder |
patch(URI url)
Create an HTTP PATCH builder with the given url.
|
static RequestEntity.BodyBuilder |
post(String uriTemplate,
Object... uriVariables)
Create an HTTP POST builder with the given string base uri template.
|
static RequestEntity.BodyBuilder |
post(URI url)
Create an HTTP POST builder with the given url.
|
static RequestEntity.BodyBuilder |
put(String uriTemplate,
Object... uriVariables)
Create an HTTP PUT builder with the given string base uri template.
|
static RequestEntity.BodyBuilder |
put(URI url)
Create an HTTP PUT builder with the given url.
|
String |
toString() |
getBody, getHeaders, hasBody
public RequestEntity(HttpMethod method, URI url)
method
- the methodurl
- the URLpublic RequestEntity(@Nullable T body, HttpMethod method, URI url)
body
- the bodymethod
- the methodurl
- the URLpublic RequestEntity(@Nullable T body, HttpMethod method, URI url, Type type)
body
- the bodymethod
- the methodurl
- the URLtype
- the type used for generic type resolutionpublic RequestEntity(MultiValueMap<String,String> headers, HttpMethod method, URI url)
headers
- the headersmethod
- the methodurl
- the URLpublic RequestEntity(@Nullable T body, @Nullable MultiValueMap<String,String> headers, @Nullable HttpMethod method, URI url)
body
- the bodyheaders
- the headersmethod
- the methodurl
- the URLpublic RequestEntity(@Nullable T body, @Nullable MultiValueMap<String,String> headers, @Nullable HttpMethod method, @Nullable URI url, @Nullable Type type)
body
- the bodyheaders
- the headersmethod
- the methodurl
- the URLtype
- the type used for generic type resolution@Nullable public HttpMethod getMethod()
HttpMethod
enum valuepublic URI getUrl()
@Nullable public Type getType()
null
if not knownpublic boolean equals(@Nullable Object other)
equals
in class HttpEntity<T>
public int hashCode()
hashCode
in class HttpEntity<T>
public String toString()
toString
in class HttpEntity<T>
public static RequestEntity.BodyBuilder method(HttpMethod method, URI url)
method
- the HTTP method (GET, POST, etc)url
- the URLpublic static RequestEntity.BodyBuilder method(HttpMethod method, String uriTemplate, Object... uriVariables)
method
- the HTTP method (GET, POST, etc)uriTemplate
- the uri template to useuriVariables
- variables to expand the URI template withpublic static RequestEntity.BodyBuilder method(HttpMethod method, String uriTemplate, Map<String,?> uriVariables)
method
- the HTTP method (GET, POST, etc)uriTemplate
- the uri template to usepublic static RequestEntity.HeadersBuilder<?> get(URI url)
url
- the URLpublic static RequestEntity.HeadersBuilder<?> get(String uriTemplate, Object... uriVariables)
uriTemplate
- the uri template to useuriVariables
- variables to expand the URI template withpublic static RequestEntity.HeadersBuilder<?> head(URI url)
url
- the URLpublic static RequestEntity.HeadersBuilder<?> head(String uriTemplate, Object... uriVariables)
uriTemplate
- the uri template to useuriVariables
- variables to expand the URI template withpublic static RequestEntity.BodyBuilder post(URI url)
url
- the URLpublic static RequestEntity.BodyBuilder post(String uriTemplate, Object... uriVariables)
uriTemplate
- the uri template to useuriVariables
- variables to expand the URI template withpublic static RequestEntity.BodyBuilder put(URI url)
url
- the URLpublic static RequestEntity.BodyBuilder put(String uriTemplate, Object... uriVariables)
uriTemplate
- the uri template to useuriVariables
- variables to expand the URI template withpublic static RequestEntity.BodyBuilder patch(URI url)
url
- the URLpublic static RequestEntity.BodyBuilder patch(String uriTemplate, Object... uriVariables)
uriTemplate
- the uri template to useuriVariables
- variables to expand the URI template withpublic static RequestEntity.HeadersBuilder<?> delete(URI url)
url
- the URLpublic static RequestEntity.HeadersBuilder<?> delete(String uriTemplate, Object... uriVariables)
uriTemplate
- the uri template to useuriVariables
- variables to expand the URI template withpublic static RequestEntity.HeadersBuilder<?> options(URI url)
url
- the URLpublic static RequestEntity.HeadersBuilder<?> options(String uriTemplate, Object... uriVariables)
uriTemplate
- the uri template to useuriVariables
- variables to expand the URI template with