Spring Boot 4 introduces the @ImportHttpServices annotation, enabling zero-boilerplate declarative HTTP clients
using @HttpExchange interfaces.
HTTP Interface Clients allow you to define REST clients as simple interfaces with declarative annotations.
Spring Boot 4's @ImportHttpServices eliminates all the manual configuration previously required.
- Zero configuration:
@ImportHttpServiceshandles all bean registrations automatically - Declarative interfaces: Define HTTP calls as method signatures with
@HttpExchange - Type-safe: Full compile-time checking with Java records
- Clean architecture: Separate interface definitions from implementation
https://github.com/danvega/sb4-http-interfaces
https://www.danvega.dev/blog/http-interfaces-spring-boot-4
@Bean
public TodoService todoService(RestClient.Builder restClientBuilder) {
var restClient = restClientBuilder
.baseUrl("https://jsonplaceholder.typicode.com")
.build();
var adapter = RestClientAdapter.create(restClient);
var factory = HttpServiceProxyFactory.builderFor(adapter).build();
return factory.createClient(TodoService.class);
}@Configuration(proxyBeanMethods = false)
@ImportHttpServices(TodoService.class)
public class HttpClientConfig {
// That's it!
}@HttpExchange(url = "https://jsonplaceholder.typicode.com", accept = "application/json")
public interface TodoService {
@GetExchange("/todos")
List<Todo> getAllTodos();
@GetExchange("/todos/{id}")
Todo getTodoById(@PathVariable Long id);
@PostExchange("/todos")
Todo createTodo(@RequestBody Todo todo);
}