接口 RestClient.RequestHeadersSpec<S extends RestClient.RequestHeadersSpec<S>>

类型参数:
S - a self reference to the spec type
所有已知子接口:
RestClient.RequestBodySpec, RestClient.RequestBodyUriSpec, RestClient.RequestHeadersUriSpec<S>
所有已知实现类:
DefaultRestClient.DefaultRequestBodyUriSpec
封闭接口:
RestClient

public static interface RestClient.RequestHeadersSpec<S extends RestClient.RequestHeadersSpec<S>>
Contract for specifying request headers leading up to the exchange.
  • 方法详细资料

    • accept

      S accept(MediaType... acceptableMediaTypes)
      Set the list of acceptable media types, as specified by the Accept header.
      参数:
      acceptableMediaTypes - the acceptable media types
      返回:
      this builder
    • acceptCharset

      S acceptCharset(Charset... acceptableCharsets)
      Set the list of acceptable charsets, as specified by the Accept-Charset header.
      参数:
      acceptableCharsets - the acceptable charsets
      返回:
      this builder
    • ifModifiedSince

      S ifModifiedSince(ZonedDateTime ifModifiedSince)
      Set the value of the If-Modified-Since header.

      The date should be specified as the number of milliseconds since January 1, 1970 GMT.

      参数:
      ifModifiedSince - the new value of the header
      返回:
      this builder
    • ifNoneMatch

      S ifNoneMatch(String... ifNoneMatches)
      Set the values of the If-None-Match header.
      参数:
      ifNoneMatches - the new value of the header
      返回:
      this builder
    • header

      S header(String headerName, String... headerValues)
      Add the given, single header value under the given name.
      参数:
      headerName - the header name
      headerValues - the header value(s)
      返回:
      this builder
    • headers

      S headers(Consumer<HttpHeaders> headersConsumer)
      Provides access to every header declared so far with the possibility to add, replace, or remove values.
      参数:
      headersConsumer - the consumer to provide access to
      返回:
      this builder
    • attribute

      S attribute(String name, Object value)
      Set the attribute with the given name to the given value.
      参数:
      name - the name of the attribute to add
      value - the value of the attribute to add
      返回:
      this builder
    • attributes

      S attributes(Consumer<Map<String,Object>> attributesConsumer)
      Provides access to every attribute declared so far with the possibility to add, replace, or remove values.
      参数:
      attributesConsumer - the consumer to provide access to
      返回:
      this builder
    • httpRequest

      S httpRequest(Consumer<ClientHttpRequest> requestConsumer)
      Callback for access to the ClientHttpRequest that in turn provides access to the native request of the underlying HTTP library.

      This could be useful for setting advanced, per-request options that are exposed by the underlying library.

      参数:
      requestConsumer - a consumer to access the ClientHttpRequest with
      返回:
      this builder
    • retrieve

      Proceed to declare how to extract the response. For example to extract a ResponseEntity with status, headers, and body:

      
       ResponseEntity<Person> entity = client.get()
           .uri("/persons/1")
           .accept(MediaType.APPLICATION_JSON)
           .retrieve()
           .toEntity(Person.class);
       

      Or if interested only in the body:

      
       Person person = client.get()
           .uri("/persons/1")
           .accept(MediaType.APPLICATION_JSON)
           .retrieve()
           .body(Person.class);
       

      By default, 4xx response code result in a HttpClientErrorException and 5xx response codes in a HttpServerErrorException. To customize error handling, use onStatus handlers.

      返回:
      ResponseSpec to specify how to decode the body
    • execute

      default void execute()
      Execute the HTTP request:

      
       client.delete()
           .uri("/persons/1")
           .execute();
       

      Or if interested only in the body:

      
        client.put()
           .uri("/persons/1")
           .body(persons)
           .execute();
       

      By default, 4xx response code result in a HttpClientErrorException and 5xx response codes in a HttpServerErrorException. To customize error handling, use onStatus handlers.

    • execute

      void execute(boolean close)
      Execute the HTTP request:

      
       client.delete()
           .uri("/persons/1")
           .execute();
       

      Or if interested only in the body:

      
        client.put()
           .uri("/persons/1")
           .body(persons)
           .execute();
       

      By default, 4xx response code result in a HttpClientErrorException and 5xx response codes in a HttpServerErrorException. To customize error handling, use onStatus handlers.

      参数:
      close - true to close the response
    • exchange

      default <T> T exchange(RestClient.RequestHeadersSpec.ExchangeFunction<T> exchangeFunction)
      Exchange the ClientHttpResponse for a type T. This can be useful for advanced scenarios, for example to decode the response differently depending on the response status:

      
       Person person = client.get()
           .uri("/people/1")
           .accept(MediaType.APPLICATION_JSON)
           .exchange((request, response) -> {
               if (response.getStatusCode().equals(HttpStatus.OK)) {
                   return deserialize(response.getBody());
               }
               else {
                   throw new BusinessException();
               }
           });
       

      Note: The response is closed after the exchange function has been invoked.

      类型参数:
      T - the type the response will be transformed to
      参数:
      exchangeFunction - the function to handle the response with
      返回:
      the value returned from the exchange function
    • exchange

      <T> T exchange(RestClient.RequestHeadersSpec.ExchangeFunction<T> exchangeFunction, boolean close)
      Exchange the ClientHttpResponse for a type T. This can be useful for advanced scenarios, for example to decode the response differently depending on the response status:

      
       Person person = client.get()
           .uri("/people/1")
           .accept(MediaType.APPLICATION_JSON)
           .exchange((request, response) -> {
               if (response.getStatusCode().equals(HttpStatus.OK)) {
                   return deserialize(response.getBody());
               }
               else {
                   throw new BusinessException();
               }
           });
       

      Note: If close is true, then the response is closed after the exchange function has been invoked. When set to false, the caller is responsible for closing the response.

      类型参数:
      T - the type the response will be transformed to
      参数:
      exchangeFunction - the function to handle the response with
      close - true to close the response after exchangeFunction is invoked, false to keep it open
      返回:
      the value returned from the exchange function