Quick revision
The short answer
Yes, I would migrate, but gradually: HTTP interface clients remove most of the wrapper boilerplate and turn each API contract into a small Java type that is easy to review. I would not have producers publish a client jar that every consumer must take, because that couples consumers to the producer's release cycle; generating clients from each producer's OpenAPI document, or letting consumers own small interfaces, avoids that. Cross-cutting concerns such as authentication, timeouts and observations belong in the configured RestClient, each API moves one at a time behind the existing service interfaces, and error mapping stays explicit so callers never see raw HTTP exceptions.
What to remember
In this answer, we decided to migrate the 30 wrappers to HTTP interface clients because the contract becomes a small reviewable type and the plumbing disappears. We avoided producer-published client jars, which tie consumers to the producer's releases, in favour of generating from OpenAPI or consumer-owned interfaces. Authentication, timeouts and observations live in the configured RestClient, the migration goes one API at a time behind the existing gateway classes, and explicit error mapping keeps raw HTTP exceptions out of business code.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Yes, I would migrate, but gradually: HTTP interface clients remove most of the wrapper boilerplate and turn each API contract into a small Java type that is easy to review. I would not have producers publish a client jar that every consumer must take, because that couples consumers to the producer's release cycle; generating clients from each producer's OpenAPI document, or letting consumers own small interfaces, avoids that. Cross-cutting concerns such as authentication, timeouts and observations belong in the configured RestClient, each API moves one at a time behind the existing service interfaces, and error mapping stays explicit so callers never see raw HTTP exceptions.
Background to this question
Thirty hand-written RestTemplate wrappers usually mean thirty slightly different ways of building URLs, adding tokens, setting timeouts and handling a 404. Every one of them works, more or less, and every one of them is a place where a bug or a missing timeout can hide. HTTP interface clients offer a cleaner model, but the interesting part of this design question is not the syntax. It is how to share client code between teams without creating a release-day dependency, and how to migrate without a risky big bang. In this answer, we will look at what the migration gains, compare the ways to share clients, decide where cross-cutting configuration lives, plan an incremental migration, and keep error handling explicit.
1What the Wrappers Look Like Today
A typical wrapper builds the URL by hand, adds a header, calls RestTemplate and translates exceptions. Multiply this by every endpoint of 30 APIs and we have thousands of lines whose only job is plumbing.
Notice that the contract, GET /stock/{sku} returning StockLevel, is buried in the plumbing. A reviewer cannot see the API at a glance, and the auth header and URL style vary between the 30 wrappers.
2What an HTTP Interface Gives Us
With an HTTP interface the contract becomes the code. The interface below says everything the wrapper said about the API in three lines, and a reviewer can compare it with the producer's documentation directly. Spring generates the implementation as a proxy on top of a RestClient, so there is no URL building or exchange call to get wrong.
The boilerplate does not disappear by magic, though. Authentication, timeouts and error handling still need a home, and that is the next decision.
3Sharing Clients Without Coupling Teams
The tempting option is for each producer team to publish an inventory-client jar with the interface and its DTOs, and for consumers to depend on it. It looks like reuse, but it couples every consumer to the producer's release cycle. A consumer that wants a bug fix must take every other change in the jar, the jar drags the producer's Jackson and Spring versions into the consumer, and a breaking change in a DTO breaks compilation in teams that do not even use that field.
Two alternatives avoid that. The producer can publish an OpenAPI document, the machine-readable description of its API, and each consumer generates its own interface and DTOs from it at build time with a generator that supports Spring HTTP interfaces, so the contract is shared but the code is not. Or each consumer writes a small interface containing only the endpoints and fields it uses, checked against the producer by contract tests. The table compares the three.
| Approach | Gain | Cost |
|---|---|---|
| Producer publishes a client jar | one place to update | consumers tied to its releases and dependencies |
| Generate from producer's OpenAPI | contract shared, code owned by consumer | spec must be accurate and versioned |
| Consumer-owned small interface | only what is used, no shared code | needs contract tests to catch drift |
4Where Cross-Cutting Concerns Live
Authentication, timeouts, base URLs, retries and observations should not appear in any interface. They belong in the RestClient each proxy is built on. We configure one RestClient per remote service, or a common builder customiser for all of them, and every interface built on it inherits the behaviour. Because RestClient is instrumented with the Observation API, metrics and traces come for free.
So one place decides how the company talks to inventory, and a platform team can ship the common pieces, such as the token interceptor, as a starter.
5Migrating One API at a Time
A big-bang rewrite of 30 wrappers would touch every caller at once. Instead, we keep the existing gateway classes, InventoryGateway and friends, as the interface the rest of the code uses, and change only their insides. Callers see no difference, and each API is one small, reviewable pull request.
- Pick the next APIstart with simple, low-risk ones
- Write or generate the HTTP interfacefrom the producer's OpenAPI if it exists
- Configure its RestClientauth, timeouts, status handler
- Reimplement the gateway on the interfacecallers unchanged
- Do the existing tests pass?YesRelease and watch error ratesNoFix mapping differences first
- Remove the old RestTemplate codeone API done, 29 to go
6 steps in order. Play them, or step through them one at a time.
The existing tests of each gateway, or a few WireMock tests added before the change, prove the behaviour is the same, including the awkward cases such as a 404 becoming StockLevel.unknown().
6Keeping Error Mapping Explicit
The old wrapper caught NotFound and returned a default. If we expose the HTTP interface directly to business code, that knowledge is lost and callers start catching HttpClientErrorException everywhere, which leaks the transport into the domain. So the gateway, or a status handler on the client, translates HTTP outcomes into domain results or domain exceptions, for example StockLevel.unknown() for a 404 and InventoryUnavailableException for a 503 or a timeout. Business code then never imports anything from the HTTP packages.
7Follow-up questions
Is generating clients from OpenAPI not just another kind of coupling?
It couples consumers to the contract, which is unavoidable, but not to the producer's code, dependencies or release cycle. A consumer regenerates when it chooses to, and a field it does not use cannot break it if the generator and the JSON mapping ignore unknown properties. That is the coupling we want.
Would you keep RestTemplate at all?
Existing RestTemplate configuration can carry HTTP interfaces through RestTemplateAdapter, which is a cheap first step if teams have carefully tuned RestTemplate beans. Over time I would move to RestClient, since RestTemplate is in maintenance mode and RestClient is where new features land.
How do you avoid 30 nearly identical configuration beans?
By putting the shared parts in a RestClient.Builder customiser and a small factory method, so each API needs only its base URL and error mapper. In Framework 7, group-based registration of HTTP service clients removes most of the remaining repetition; check the API for your version.
8Conclusion
In this answer, we decided to migrate the 30 wrappers to HTTP interface clients because the contract becomes a small reviewable type and the plumbing disappears. We avoided producer-published client jars, which tie consumers to the producer's releases, in favour of generating from OpenAPI or consumer-owned interfaces. Authentication, timeouts and observations live in the configured RestClient, the migration goes one API at a time behind the existing gateway classes, and explicit error mapping keeps raw HTTP exceptions out of business code.
Open with
Yes, I would migrate, but incrementally. Today the contract of each API is hidden inside URL building, headers and exchange calls, and each of the 30 wrappers does auth and timeouts slightly differently.
Then, if they want more
An HTTP interface makes the contract a three-line Java type that is easy to review, and Spring generates the implementation on top of a RestClient.
On sharing, I would avoid having producers publish client jars that consumers depend on, because then every consumer is tied to the producer's release cycle and dependencies, and a DTO change can break teams that do not use it.
I prefer that producers publish an accurate OpenAPI document and consumers generate their own interfaces from it, or write small interfaces with only what they use, backed by contract tests. Cross-cutting concerns go into the RestClient each proxy is built on: base URL, a token interceptor, connect and read timeouts, a status handler, and observations, which RestClient gives us automatically.
Then I migrate one API at a time behind the existing gateway classes, so callers do not change and the existing tests prove the behaviour, including cases like a 404 that becomes an unknown result. Finally I keep error mapping explicit, translating HTTP failures into domain results or exceptions so business code never sees HttpClientErrorException.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Framework reference, Core technologies
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Your company has hand-written RestTemplate wrappers for 30 internal APIs. Would you...": https://scrivio-interview-library.netlify.app/spring-boot/spring-framework-evolution/a0fd984d7c/