rrezartprebreza/spring-boot-skills / skills/spring-boot-3/http-interface-clients
http-interface-clients
VerifiedUse when calling external HTTP APIs from Spring Boot 3 / Spring Framework 6 with declarative HttpExchange interfaces. Covers manual proxy registration, RestClient versus WebClient, and timeout and error handling conventions.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 4.0 KB |
| agents/openai.yaml | config | 204 B |
| examples/bad-order-client.java | other | 148 B |
| examples/good-order-client.java | other | 197 B |
| templates/CatalogHttpClient.java | other | 2.7 KB |
templates/CatalogHttpClient.java
View on GitHubpackage com.example.clients;
import java.net.ConnectException;
import java.net.URI;
import java.net.SocketTimeoutException;
import java.net.http.HttpClient;
import java.net.http.HttpTimeoutException;
import java.time.Duration;
import java.util.UUID;
import java.util.concurrent.CancellationException;
import org.springframework.http.client.JdkClientHttpRequestFactory;
import org.springframework.web.client.HttpServerErrorException;
import org.springframework.web.client.ResourceAccessException;
import org.springframework.web.client.RestClient;
import com.example.clients.CatalogRetryService.CatalogTransport;
import com.example.clients.CatalogRetryService.TransientCatalogException;
/** Error classification belongs in the transport adapter, not in controllers. */
public final class CatalogHttpClient implements CatalogTransport {
private final RestClient client;
public CatalogHttpClient(RestClient client) { this.client = client; }
public static CatalogHttpClient create(URI baseUrl, Duration connectTimeout, Duration readTimeout) {
if (connectTimeout == null || readTimeout == null || connectTimeout.isNegative()
|| connectTimeout.isZero() || readTimeout.isNegative() || readTimeout.isZero()) {
throw new IllegalArgumentException("Positive transport timeouts required");
}
var http = HttpClient.newBuilder().connectTimeout(connectTimeout).build();
var factory = new JdkClientHttpRequestFactory(http);
factory.setReadTimeout(readTimeout);
return new CatalogHttpClient(RestClient.builder().baseUrl(baseUrl.toString()).requestFactory(factory).build());
}
@Override public String fetch(UUID id) {
try {
return client.get().uri("/catalog/{id}", id).retrieve().body(String.class);
} catch (HttpServerErrorException failure) {
int status = failure.getStatusCode().value();
if (status == 502 || status == 503 || status == 504) {
throw new TransientCatalogException(failure);
}
throw failure;
} catch (ResourceAccessException failure) {
boolean transientFailure = false;
for (Throwable cause = failure; cause != null; cause = cause.getCause()) {
if (cause instanceof InterruptedException) {
Thread.currentThread().interrupt();
throw new CancellationException("Interrupted");
}
transientFailure |= cause instanceof ConnectException
|| cause instanceof SocketTimeoutException || cause instanceof HttpTimeoutException;
}
if (transientFailure) throw new TransientCatalogException(failure);
throw failure;
}
}
}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementation | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirements | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallback | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |