Skip to content

Latest commit

 

History

History
73 lines (52 loc) · 1.89 KB

File metadata and controls

73 lines (52 loc) · 1.89 KB

Spring HTTP Interface Auto Create Proxy Service

Spring HTTP Interface is an HTTP service as a Java interface with annotated methods for HTTP exchanges.

Add annotation @HttpInterface for @HttpExchange(s).

Add annotation @EnableHttpInterfaces for init beans with annotation @HttpInterface.

Requirements

  • Spring Framework 6/Spring Boot 3
  • Java 17+

How to use

Annotation interface by @HttpInterface

@HttpInterface(baseUrl = "http://127.0.0.1:8080")
public interface GreetingService {

    @GetExchange("/greeting")
    Mono<String> greeting(@RequestParam String name);
}

Use GreetingService to communicate with HTTP Server

@AllArgsConstructor
@RestController
public static class GreetingEndpoint {

    private GreetingService greetingService;

    @RequestMapping("/hello")
    public Mono<String> greeting(@RequestParam String name) {
        return greetingService.greeting(name);
    }

    @RequestMapping("/greeting")
    public Mono<String> hello(@RequestParam String name) {
        return Mono.just("Hello " + name);
    }
}

More about @HttpInterface

Use you own HttpServiceProxyFactory

@HttpInterface(proxyFactory = "myProxyFactory")
public interface GreetingService {

    @GetExchange("/greeting")
    Mono<String> greeting(@RequestParam String name);
}

Use you own WebClient

@HttpInterface(httpExchangeAdapter = "myHttpExchangeAdapter")
public interface GreetingService {

    @GetExchange("/greeting")
    Mono<String> greeting(@RequestParam String name);
}

Learn More