接口 RestClient.RequestHeadersSpec<S extends RestClient.RequestHeadersSpec<S>>
- 类型参数:
S- a self reference to the spec type
- 所有已知子接口:
RestClient.RequestBodySpec,RestClient.RequestBodyUriSpec,RestClient.RequestHeadersUriSpec<S>
- 封闭接口:
- RestClient
-
嵌套类概要
嵌套类 -
方法概要
修饰符和类型方法说明Set the list of acceptable media types, as specified by theAcceptheader.acceptCharset(Charset... acceptableCharsets) Set the list of acceptable charsets, as specified by theAccept-Charsetheader.Set the attribute with the given name to the given value.attributes(Consumer<Map<String, Object>> attributesConsumer) Provides access to every attribute declared so far with the possibility to add, replace, or remove values.default <T> Texchange(RestClient.RequestHeadersSpec.ExchangeFunction<T> exchangeFunction) Exchange theClientHttpResponsefor a typeT.<T> Texchange(RestClient.RequestHeadersSpec.ExchangeFunction<T> exchangeFunction, boolean close) Exchange theClientHttpResponsefor a typeT.default voidexecute()Execute the HTTP request:voidexecute(boolean close) Execute the HTTP request:Add the given, single header value under the given name.headers(Consumer<HttpHeaders> headersConsumer) Provides access to every header declared so far with the possibility to add, replace, or remove values.httpRequest(Consumer<ClientHttpRequest> requestConsumer) Callback for access to theClientHttpRequestthat in turn provides access to the native request of the underlying HTTP library.ifModifiedSince(ZonedDateTime ifModifiedSince) Set the value of theIf-Modified-Sinceheader.ifNoneMatch(String... ifNoneMatches) Set the values of theIf-None-Matchheader.retrieve()Proceed to declare how to extract the response.
-
方法详细资料
-
accept
Set the list of acceptable media types, as specified by theAcceptheader.- 参数:
acceptableMediaTypes- the acceptable media types- 返回:
- this builder
-
acceptCharset
Set the list of acceptable charsets, as specified by theAccept-Charsetheader.- 参数:
acceptableCharsets- the acceptable charsets- 返回:
- this builder
-
ifModifiedSince
Set the value of theIf-Modified-Sinceheader.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
Set the values of theIf-None-Matchheader.- 参数:
ifNoneMatches- the new value of the header- 返回:
- this builder
-
header
Add the given, single header value under the given name.- 参数:
headerName- the header nameheaderValues- the header value(s)- 返回:
- this builder
-
headers
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
Set the attribute with the given name to the given value.- 参数:
name- the name of the attribute to addvalue- the value of the attribute to add- 返回:
- this builder
-
attributes
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
Callback for access to theClientHttpRequestthat 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 theClientHttpRequestwith- 返回:
- this builder
-
retrieve
RestClient.ResponseSpec retrieve()Proceed to declare how to extract the response. For example to extract aResponseEntitywith 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
HttpClientErrorExceptionand 5xx response codes in aHttpServerErrorException. To customize error handling, useonStatushandlers.- 返回:
ResponseSpecto 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
HttpClientErrorExceptionand 5xx response codes in aHttpServerErrorException. To customize error handling, useonStatushandlers. -
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
HttpClientErrorExceptionand 5xx response codes in aHttpServerErrorException. To customize error handling, useonStatushandlers.- 参数:
close-trueto close the response
-
exchange
Exchange theClientHttpResponsefor a typeT. 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
Exchange theClientHttpResponsefor a typeT. 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
closeistrue, then the response is closed after the exchange function has been invoked. When set tofalse, the caller is responsible for closing the response.- 类型参数:
T- the type the response will be transformed to- 参数:
exchangeFunction- the function to handle the response withclose-trueto close the response afterexchangeFunctionis invoked,falseto keep it open- 返回:
- the value returned from the exchange function
-