Skip to content

Releases: maciejwalkowiak/spring-boot-http-clients

v0.1.1

30 Oct 16:42
Compare
Choose a tag to compare

What's Changed

  • Customization of Headers, Cookies and Filters by @babltiga in #5
  • Update README file: proofread and add some emojis by @cookabc in #2

New Contributors

Full Changelog: v0.1.0...v0.1.1

v0.1.0

07 Apr 09:44
Compare
Choose a tag to compare

🤔 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

  1. Define HTTP clients in application.yml or application.properties under the prefix http.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.

  1. 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();
}
  1. That's it! Now you can inject TodoClient anywhere in your code