2021-05-04 13:01:20 -07:00

30 lines
1.4 KiB
Plaintext

[[howto.http-clients]]
== HTTP Clients
Spring Boot offers a number of starters that work with HTTP clients.
This section answers questions related to using them.
[[howto.http-clients.rest-template-proxy-configuration]]
=== Configure RestTemplate to Use a Proxy
As described in <<features#features.resttemplate.customization>>, you can use a `RestTemplateCustomizer` with `RestTemplateBuilder` to build a customized `RestTemplate`.
This is the recommended approach for creating a `RestTemplate` configured to use a proxy.
The exact details of the proxy configuration depend on the underlying client request factory that is being used.
[[howto.http-clients.webclient-reactor-netty-customization]]
=== Configure the TcpClient used by a Reactor Netty-based WebClient
When Reactor Netty is on the classpath a Reactor Netty-based `WebClient` is auto-configured.
To customize the client's handling of network connections, provide a `ClientHttpConnector` bean.
The following example configures a 60 second connect timeout and adds a `ReadTimeoutHandler`:
[source,java,indent=0,subs="verbatim"]
----
include::{docs-java}/howto/httpclients/webclientreactornettycustomization/MyReactorNettyClientConfiguration.java[]
----
TIP: Note the use of `ReactorResourceFactory` for the connection provider and event loop resources.
This ensures efficient sharing of resources for the server receiving requests and the client making requests.