Backend Development 11 min read

Using Spring 6 HTTP Interface (GetExchange) to Build a Demo Service

This article introduces Spring 6's new HTTP Interface feature with a step‑by‑step demo, explains the GetExchange annotation and service creation, and then shifts to promote AI‑related products and community offers, including code snippets and deployment instructions.

Top Architect
Top Architect
Top Architect
Using Spring 6 HTTP Interface (GetExchange) to Build a Demo Service

Spring 6’s first GA release adds a new HTTP Interface feature that lets developers define HTTP services as Java interfaces annotated with specific markers, similar to Feign but integrated into Spring.

Demo Overview

First, create a simple Spring Boot project (version 3.0+ with Java 17) and add the spring-web and spring-webflux (Reactive Web) dependencies.

Entity Class

public class User implements Serializable {
    private int id;
    private String name;
    // constructors, getters, setters omitted
    @Override
    public String toString() {
        return id + ":" + name;
    }
}

Controller

@GetMapping("/users")
public List
list() {
    return IntStream.rangeClosed(1, 10)
        .mapToObj(i -> new User(i, "User" + i))
        .collect(Collectors.toList());
}

After starting the service, http://localhost:8080/users returns a list of ten users.

HTTP Interface Definition

public interface UserApiService {
    @GetExchange("/users")
    List
getUsers();
}

Testing the Interface

@Test
void getUsers() {
    WebClient client = WebClient.builder().baseUrl("http://localhost:8080/").build();
    HttpServiceProxyFactory factory = HttpServiceProxyFactory.builder(WebClientAdapter.forClient(client)).build();
    UserApiService service = factory.createClient(UserApiService.class);
    List
users = service.getUsers();
    for (User user : users) {
        System.out.println(user);
    }
}

The test prints user entries such as 1:User1 … 10:User10 .

GetExchange Annotation

The @GetExchange annotation (and its siblings) lives in org.springframework.web.service.annotation within the spring-web module. Its source defines attributes like value / url , method , contentType , and accept .

Creating the Service Instance

Instances of the HTTP Interface are created via HttpServiceProxyFactory , which returns a dynamic proxy similar to Spring MVC’s @RequestMapping handling. Future Spring versions may provide more convenient factory methods.

Additional Features

Methods annotated with @HttpExchange can accept various parameters, return any custom type, and support custom exception handling, mirroring Spring MVC controller capabilities.

Why Reactive Web Dependency?

Currently the HTTP Interface implementation relies on WebClient from Spring Reactive Web; a RestTemplate‑based implementation is planned for later releases.

Summary

The article demonstrates the basic usage of Spring 6’s HTTP Interface, explains the @GetExchange annotation, shows how to create and test a service proxy, and notes the need for Reactive Web dependencies.

Promotional Section

The latter part of the content shifts to marketing, offering AI‑related products, a paid “DeepSeek” practical collection, exclusive ChatGPT accounts, and a community “AI Club” with various benefits, discounts, and recruitment calls.

It includes multiple calls‑to‑action, QR codes, and links encouraging readers to purchase services, join groups, or download supplemental materials.

Javabackend developmentSpring BootHttp InterfaceGetExchange
Top Architect
Written by

Top Architect

Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.