Skip to content

Commit 89b0a5f

Browse files
committed
docs(client-adoption): add client-side integration guide with adapter pattern and quick start config
1 parent effdcdf commit 89b0a5f

File tree

1 file changed

+33
-14
lines changed

1 file changed

+33
-14
lines changed

docs/adoption/client-side-adoption.md

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ package
131131
<your.base>.openapi.client.adapter;
132132

133133
import <your.base>.openapi.client.common.ServiceClientResponse;
134-
import <your.base>.openapi.client.generated.dto .*;
134+
import <your.base>.openapi.client.generated.dto.*;
135135

136136
public interface YourClientAdapter {
137137
ServiceClientResponse<YourDto> getYourEntity(Integer id);
@@ -144,19 +144,17 @@ This shields your business code from generated artifacts and provides a stable c
144144

145145
---
146146

147-
## 7) Spring Boot Configuration (Optional)
147+
7) Spring Boot Configuration — Quick Start (for demos/dev)
148148

149-
Example auto-wiring configuration:
149+
For quick experiments or local development, you can wire the generated client with a simple RestClient:
150150

151151
```java
152-
153152
@Configuration
154153
public class YourApiClientConfig {
155154

156155
@Bean
157-
RestClient yourRestClient(RestClient.Builder builder,
158-
@Value("${your.api.base-url}") String baseUrl) {
159-
return builder.baseUrl(baseUrl).build();
156+
RestClient yourRestClient(RestClient.Builder builder) {
157+
return builder.build();
160158
}
161159

162160
@Bean
@@ -178,20 +176,41 @@ public class YourApiClientConfig {
178176
your.api.base-url=http://localhost:8084/your-service
179177
```
180178

179+
> **Note:** This setup is for **demos/local development**.
180+
> For production, encapsulate `YourControllerApi` behind an **Adapter interface** and use a **pooled HTTP client** (e.g., Apache HttpClient5).
181181
---
182182

183183
## 8) Usage Example
184184

185185
```java
186+
package <your.base>.openapi.client.usecase;
187+
188+
import <your.base>.openapi.client.adapter.YourClientAdapter;
189+
import <your.base>.openapi.client.common.ServiceClientResponse;
190+
import <your.base>.openapi.client.generated.dto.YourCreateRequest;
191+
import <your.base>.openapi.client.generated.dto.YourCreateResponse;
192+
import org.springframework.stereotype.Component;
186193

187-
@Autowired
188-
private YourControllerApi yourApi;
194+
@Component
195+
public class DemoUseCase {
189196

190-
public void demo() {
191-
var req = new YourCreateRequest().name("Alice");
192-
var resp = yourApi.createYourEntity(req);
193-
System.out.println(resp.getStatus());
194-
System.out.println(resp.getData().getName());
197+
private final YourClientAdapter yourClient;
198+
199+
public DemoUseCase(YourClientAdapter yourClient) {
200+
this.yourClient = yourClient;
201+
}
202+
203+
public void run() {
204+
YourCreateRequest req = new YourCreateRequest();
205+
req.setName("Alice");
206+
207+
ServiceClientResponse<YourCreateResponse> resp = yourClient.createYourEntity(req);
208+
209+
var payload = resp.getData();
210+
var response = yourClient.createYourEntity(req);
211+
var data = response.getData();
212+
log.info("Created entity id={} name={}", data.getId(), data.getName());
213+
}
195214
}
196215
```
197216

0 commit comments

Comments
 (0)