spring-projects / spring-framework

Spring Framework
https://spring.io/projects/spring-framework
Apache License 2.0
55.27k stars 37.62k forks source link

Rest Http Interface configuration is verbose #32741

Closed michaelisvy closed 2 weeks ago

michaelisvy commented 2 weeks ago

Affects: Spring framwework 6.1.6

In a sample project, I have put side by side the new RestClient and the Http interface (which allows to use annotations such as @GetExchange)

    @Bean
    public RestClient restClient() {
        return RestClient.create();
    }

    @Bean
    StudentService invoiceServiceWithHttpInterface() {
        var restClient = RestClient.builder().baseUrl(endpointUrl).build();
        var adapter = RestClientAdapter.create(restClient);
        var factory = HttpServiceProxyFactory.builderFor(adapter).build();
        return factory.createClient(StudentService.class);
    }

Would there be a way to make the HttpInterface configuration more intuitive? Something like that would be nice:

@Bean
public StudentService invoiceServiceWithHttpInterface() {
    return RestHttpInterface.createClient(StudentService.class);
}

Great thanks!

snicoll commented 2 weeks ago

Please vote for https://github.com/spring-projects/spring-boot/issues/31337 as it would avoid the boilerplate that you're talking about. 3 lines of code doesn't sound too bad to me (straight from the reference guide, so easy to find).

We shouldn't introduce additional high-level concepts in the core framework just so that the above can be written in one line instead of 3.

michaelisvy commented 2 weeks ago

sure, thanks for your prompt answer! I agree it would be nicer to have an @Enable... annotation. I've subscribed to https://github.com/spring-projects/spring-boot/issues/31337