spring-boot-http-clients

Spring Boot HTTP Clients provides zero-boilerplate auto-configuration for WebClient and Spring 6 HTTP Interface based HTTP clients in a Spring Boot application.

MIT License

Stars
101

Bot releases are hidden (Show)

spring-boot-http-clients - v0.1.1 Latest Release

Published by maciejwalkowiak 12 months ago

What's Changed

New Contributors

Full Changelog: https://github.com/maciejwalkowiak/spring-boot-http-clients/compare/v0.1.0...v0.1.1

spring-boot-http-clients - v0.1.0

Published by maciejwalkowiak over 1 year ago

🤔 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
Related Projects