Releases: maciejwalkowiak/spring-boot-http-clients
Releases · maciejwalkowiak/spring-boot-http-clients
v0.1.1
v0.1.0
🤔 How to install
Then, add the dependency to spring-boot-http-clients
:
<dependency>
<groupId>com.maciejwalkowiak.spring</groupId>
<artifactId>spring-boot-http-clients</artifactId>
<version>0.1.0</version>
</dependency>
✨ How to use
- Define HTTP clients in
application.yml
orapplication.properties
under the prefixhttp.clients
:
http.clients:
todo-client:
url: https://jsonplaceholder.typicode.com/todos
user-client:
url: https://jsonplaceholder.typicode.com/users
The client names (in the above example, todo-client
and user-client
) are just strings - use anything that makes sense - they are going to be used to construct the WebClient
bean name.
The above code gets processed by WebClientsAutoConfiguration
, which creates a bean of type WebClient
with the name <client-name>.WebClient
.
- Define an HTTP client with Spring 6 HTTP Interface, annotate it with
@HttpClient
, and set the client name as the parameter:
@HttpClient("todo-client")
public interface TodoClient {
@GetExchange
List<Todo> get();
}
- That's it! Now you can inject
TodoClient
anywhere in your code