类 RequestEntity<T>

java.lang.Object
cn.taketoday.http.HttpEntity<T>
cn.taketoday.http.RequestEntity<T>
类型参数:
T - the body type
直接已知子类:
RequestEntity.UriTemplateRequestEntity

public class RequestEntity<T> extends HttpEntity<T>
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();
 }
 
从以下版本开始:
4.0 2021/11/5 21:46
作者:
Arjen Poutsma, Sebastien Deleuze, Parviz Rozikov, Harry Yang
另请参阅:
  • 字段详细资料

    • method

      @Nullable private final HttpMethod method
    • url

      @Nullable private final URI url
    • type

      @Nullable private final Type type
  • 构造器详细资料

    • RequestEntity

      public RequestEntity(HttpMethod method, URI url)
      Constructor with method and URL but without body nor headers.
      参数:
      method - the method
      url - the URL
    • RequestEntity

      public RequestEntity(@Nullable T body, HttpMethod method, URI url)
      Constructor with method, URL and body but without headers.
      参数:
      body - the body
      method - the method
      url - the URL
    • RequestEntity

      public RequestEntity(@Nullable T body, HttpMethod method, URI url, Type type)
      Constructor with method, URL, body and type but without headers.
      参数:
      body - the body
      method - the method
      url - the URL
      type - the type used for generic type resolution
    • RequestEntity

      public RequestEntity(cn.taketoday.util.MultiValueMap<String,String> headers, HttpMethod method, URI url)
      Constructor with method, URL and headers but without body.
      参数:
      headers - the headers
      method - the method
      url - the URL
    • RequestEntity

      public RequestEntity(@Nullable T body, @Nullable cn.taketoday.util.MultiValueMap<String,String> headers, @Nullable HttpMethod method, URI url)
      Constructor with method, URL, headers and body.
      参数:
      body - the body
      headers - the headers
      method - the method
      url - the URL
    • RequestEntity

      public RequestEntity(@Nullable T body, @Nullable cn.taketoday.util.MultiValueMap<String,String> headers, @Nullable HttpMethod method, @Nullable URI url, @Nullable Type type)
      Constructor with method, URL, headers, body and type.
      参数:
      body - the body
      headers - the headers
      method - the method
      url - the URL
      type - the type used for generic type resolution
  • 方法详细资料

    • getMethod

      @Nullable public HttpMethod getMethod()
      Return the HTTP method of the request.
      返回:
      the HTTP method as an HttpMethod enum value
    • getUrl

      public URI getUrl()
      Return the URI for the target HTTP endpoint.

      Note: This method raises UnsupportedOperationException if the RequestEntity was created with a URI template and variables rather than with a URI instance. This is because a URI cannot be created without further input on how to expand template and encode the URI. In such cases, the URI is prepared by the RestTemplate with the help of the UriTemplateHandler it is configured with.

    • getType

      @Nullable public Type getType()
      Return the type of the request's body.
      返回:
      the request's body type, or null if not known
    • equals

      public boolean equals(@Nullable Object other)
      覆盖:
      equals 在类中 HttpEntity<T>
    • hashCode

      public int hashCode()
      覆盖:
      hashCode 在类中 HttpEntity<T>
    • toString

      public String toString()
      覆盖:
      toString 在类中 HttpEntity<T>
    • format

      static <T> String format(@Nullable HttpMethod httpMethod, String url, @Nullable T body, HttpHeaders headers)
    • method

      public static RequestEntity.BodyBuilder method(HttpMethod method, URI url)
      Create a builder with the given method and url.
      参数:
      method - the HTTP method (GET, POST, etc)
      url - the URL
      返回:
      the created builder
    • method

      public static RequestEntity.BodyBuilder method(HttpMethod method, String uriTemplate, Object... uriVariables)
      Create a builder with the given HTTP method, URI template, and variables.
      参数:
      method - the HTTP method (GET, POST, etc)
      uriTemplate - the uri template to use
      uriVariables - variables to expand the URI template with
      返回:
      the created builder
    • method

      public static RequestEntity.BodyBuilder method(HttpMethod method, String uriTemplate, Map<String,?> uriVariables)
      Create a builder with the given HTTP method, URI template, and variables.
      参数:
      method - the HTTP method (GET, POST, etc)
      uriTemplate - the uri template to use
      返回:
      the created builder
    • get

      public static RequestEntity.HeadersBuilder<?> get(URI url)
      Create an HTTP GET builder with the given url.
      参数:
      url - the URL
      返回:
      the created builder
    • get

      public static RequestEntity.HeadersBuilder<?> get(String uriTemplate, Object... uriVariables)
      Create an HTTP GET builder with the given string base uri template.
      参数:
      uriTemplate - the uri template to use
      uriVariables - variables to expand the URI template with
      返回:
      the created builder
    • head

      public static RequestEntity.HeadersBuilder<?> head(URI url)
      Create an HTTP HEAD builder with the given url.
      参数:
      url - the URL
      返回:
      the created builder
    • head

      public static RequestEntity.HeadersBuilder<?> head(String uriTemplate, Object... uriVariables)
      Create an HTTP HEAD builder with the given string base uri template.
      参数:
      uriTemplate - the uri template to use
      uriVariables - variables to expand the URI template with
      返回:
      the created builder
    • post

      public static RequestEntity.BodyBuilder post(URI url)
      Create an HTTP POST builder with the given url.
      参数:
      url - the URL
      返回:
      the created builder
    • post

      public static RequestEntity.BodyBuilder post(String uriTemplate, Object... uriVariables)
      Create an HTTP POST builder with the given string base uri template.
      参数:
      uriTemplate - the uri template to use
      uriVariables - variables to expand the URI template with
      返回:
      the created builder
    • put

      public static RequestEntity.BodyBuilder put(URI url)
      Create an HTTP PUT builder with the given url.
      参数:
      url - the URL
      返回:
      the created builder
    • put

      public static RequestEntity.BodyBuilder put(String uriTemplate, Object... uriVariables)
      Create an HTTP PUT builder with the given string base uri template.
      参数:
      uriTemplate - the uri template to use
      uriVariables - variables to expand the URI template with
      返回:
      the created builder
    • patch

      public static RequestEntity.BodyBuilder patch(URI url)
      Create an HTTP PATCH builder with the given url.
      参数:
      url - the URL
      返回:
      the created builder
    • patch

      public static RequestEntity.BodyBuilder patch(String uriTemplate, Object... uriVariables)
      Create an HTTP PATCH builder with the given string base uri template.
      参数:
      uriTemplate - the uri template to use
      uriVariables - variables to expand the URI template with
      返回:
      the created builder
    • delete

      public static RequestEntity.HeadersBuilder<?> delete(URI url)
      Create an HTTP DELETE builder with the given url.
      参数:
      url - the URL
      返回:
      the created builder
    • delete

      public static RequestEntity.HeadersBuilder<?> delete(String uriTemplate, Object... uriVariables)
      Create an HTTP DELETE builder with the given string base uri template.
      参数:
      uriTemplate - the uri template to use
      uriVariables - variables to expand the URI template with
      返回:
      the created builder
    • options

      public static RequestEntity.HeadersBuilder<?> options(URI url)
      Creates an HTTP OPTIONS builder with the given url.
      参数:
      url - the URL
      返回:
      the created builder
    • options

      public static RequestEntity.HeadersBuilder<?> options(String uriTemplate, Object... uriVariables)
      Creates an HTTP OPTIONS builder with the given string base uri template.
      参数:
      uriTemplate - the uri template to use
      uriVariables - variables to expand the URI template with
      返回:
      the created builder
      从以下版本开始:
      4.0