Package enterprises.iwakura.kirara.core
Class HttpCore
java.lang.Object
enterprises.iwakura.kirara.core.HttpCore
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
HttpUrlConnectionHttpCore
Abstract class representing the core of Kirara's HTTP backend. Used to send the actual HTTP requests.
This class is designed to be extended by specific HTTP implementations (e.g., OkHttp, etc.)
The Kirara Core implements Java 8's
The Kirara Core implements Java 8's
HttpURLConnection in HttpUrlConnectionHttpCore-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract voidclose()Closes the HTTP core, releasing any resources it holds.protected byte[]convertBodyToBytes(Kirara kirara, Object body) Converts the body of an API request to a byte array.protected <T> TconvertBytesToResponse(Kirara kirara, byte[] response, Class<T> specifiedResponseClass, Map<String, List<String>> responseHeaders) Converts a byte array response to an object of the specified class using the Kirara serializer.Returns an executor that can be used to schedule API requests.protected <T> ThandleKiraraSupportedResponse(Kirara kirara, T response) Handles the response for Kirara-supported responses by setting the Kirara instance on the response.abstract <T> CompletableFuture<T> send(ApiRequest<T> request) Sends an API request and returns a CompletableFuture that will be completed with the response.
-
Field Details
-
executor
The executor to schedule API requests on.
-
-
Constructor Details
-
HttpCore
public HttpCore()Default constructor for HttpCore. This can be overridden by subclasses if needed.
-
-
Method Details
-
send
Sends an API request and returns a CompletableFuture that will be completed with the response.- Type Parameters:
T- The type of the response expected from the API.- Parameters:
request- The API request to send.- Returns:
- A CompletableFuture that will be completed with the response.
-
close
public abstract void close()Closes the HTTP core, releasing any resources it holds.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
getExecutor
Returns an executor that can be used to schedule API requests.- Returns:
- An Executor that can be used to schedule API requests.
-
convertBodyToBytes
Converts the body of an API request to a byte array. Default implementation handles byte arrays and Strings, and uses the serializer for other object types.- Parameters:
kirara- The Kirara instance used for serialization.body- The body of the API request, which can be of various types (e.g., byte[], String, or any object).- Returns:
- A byte array representation of the body.
-
convertBytesToResponse
protected <T> T convertBytesToResponse(Kirara kirara, byte[] response, Class<T> specifiedResponseClass, Map<String, List<String>> responseHeaders) Converts a byte array response to an object of the specified class using the Kirara serializer.- Type Parameters:
T- The type of the object to deserialize into.- Parameters:
kirara- The Kirara instance used for deserialization.response- The byte array response to convert.specifiedResponseClass- The class to deserialize into.responseHeaders- The headers associated with the response, used for content type detection.- Returns:
- The deserialized object of the specified class.
-
handleKiraraSupportedResponse
Handles the response for Kirara-supported responses by setting the Kirara instance on the response.- Type Parameters:
T- The type of the response.- Parameters:
kirara- The Kirara instance associated with the request.response- The response to handle.- Returns:
- The response with the Kirara instance set, if applicable.
-