Skip to content

What is CoApi? ​

Spring's HTTP Interface lets you declare an HTTP API as a Java/Kotlin interface with @HttpExchange methods. To call it, something still has to build an HTTP client, wrap it in an adapter, create a proxy with HttpServiceProxyFactory and register that proxy as a bean, once per interface.

CoApi does that wiring for you. Annotate the interface with @CoApi, and you can inject it:

kotlin
@CoApi(baseUrl = "\${github.url}")
interface GitHubApiClient {
    @GetExchange("repos/{owner}/{repo}/issues")
    fun getIssues(@PathVariable owner: String, @PathVariable repo: String): Flux<Issue>
}

@RestController
class IssueController(private val gitHubApiClient: GitHubApiClient)

What you get ​

CapabilityHow
One injectable proxy per interface, no factory code@CoApi + Spring Boot auto-configuration, or @EnableCoApi
Reactive or blockingWebClient or RestClient, chosen by coapi.mode or inferred from the classpath
Client-side load balancingserviceId, lb:// or @LoadBalanced, via Spring Cloud LoadBalancer
Per-client settings without codecoapi.clients.<name>.* overrides base URL, load balancing, filters and interceptors
Global hooksWebClientBuilderCustomizer / RestClientBuilderCustomizer beans
Token authenticationBearerTokenFilter with a refreshing token cache (reactive)

When to use it ​

CoApi fits when you call several HTTP APIs through typed interfaces and want each one to be a bean with minimal setup, in either programming model. In particular:

  • Reactive applications. Spring Cloud OpenFeign has no reactive support. CoApi treats WebClient as a first-class option.
  • Shared contracts. A provider can implement an @HttpExchange interface, and consumers extend it with @CoApi (see Examples).
  • Service discovery. Point a client at a serviceId instead of a host.

CoApi is not the right tool for WebSocket or SSE clients, for resilience policies (retry, circuit breaking: use filters/interceptors with a library such as Resilience4j), or for one-off calls where a typed interface adds nothing. Use WebClient or RestClient directly for those.

How it works ​

For every client interface, CoApi registers two beans:

  1. <name>.HttpClient: a WebClient or RestClient built with the client's base URL, its filters or interceptors, and load balancing when enabled.
  2. <name>.CoApi: the interface proxy created by HttpServiceProxyFactory on top of that client. This is the bean you inject.

<name> is @CoApi(name), or the interface's simple name by default. Architecture describes the full registration flow.

Version compatibility ​

CoApiSpring BootSpring FrameworkJDK
3.x4.x7.x17+
2.x4.x7.x17+
1.x3.2.x6.1.x17+

The current line is tested on JDK 17, 21 and 25. Upgrading from 2.x? Read Migrating to 3.0.

Next steps ​