Package com.guinetik.rr.http
Interface RocketClient
-
- All Known Implementing Classes:
AsyncHttpClient,CircuitBreakerClient,DefaultHttpClient,FluentHttpClient,InterceptingClient,MockRocketClient
public interface RocketClientCore interface for HTTP request execution in RocketRest.This abstraction allows different HTTP client implementations while maintaining a consistent API. The default implementation uses Java's
HttpURLConnection, but custom implementations can be provided.Implementations
DefaultHttpClient- Synchronous client using HttpURLConnectionAsyncHttpClient- Wraps any RocketClient for async executionFluentHttpClient- ReturnsResultinstead of exceptionsCircuitBreakerClient- Decorator adding circuit breaker resilienceMockRocketClient- For testing without real HTTP calls
Creating Clients
// Via factory (recommended) RocketClient client = RocketClientFactory.builder("https://api.example.com") .withOptions(options) .withCircuitBreaker(5, 30000) .build(); // Execute request RequestSpec<Void, User> request = RequestBuilder.get("/users/1") .responseType(User.class) .build(); User user = client.execute(request);Custom Implementation
public class OkHttpRocketClient implements RocketClient { private final OkHttpClient okHttp = new OkHttpClient(); @Override public <Req, Res> Res execute(RequestSpec<Req, Res> spec) { // Implement using OkHttp } // ... other methods }- Since:
- 1.0.0
- Author:
- guinetik <guinetik@gmail.com>
- See Also:
RocketClientFactory,DefaultHttpClient
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidconfigureSsl(SSLContext sslContext)Sets the SSL context to be used for HTTPS requests.<Req,Res>
Resexecute(RequestSpec<Req,Res> requestSpec)Executes an HTTP request based on the provided request specification.voidsetBaseUrl(String baseUrl)
-
-
-
Method Detail
-
execute
<Req,Res> Res execute(RequestSpec<Req,Res> requestSpec) throws RocketRestException
Executes an HTTP request based on the provided request specification.- Type Parameters:
Req- The type of the request body.Res- The type of the response.- Parameters:
requestSpec- The specification of the request to be executed.- Returns:
- The response object.
- Throws:
RocketRestException- If an error occurs during the request execution.
-
configureSsl
void configureSsl(SSLContext sslContext)
Sets the SSL context to be used for HTTPS requests.- Parameters:
sslContext- The SSL context to use.
-
setBaseUrl
void setBaseUrl(String baseUrl)
-
-