Skip to content

40CoderPlus/http-exchange-spring-boot

Repository files navigation

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages