Package enterprises.iwakura.kirara.core
Class ApiRequest<T>
java.lang.Object
enterprises.iwakura.kirara.core.ApiRequest<T>
- Type Parameters:
T- the type of the response expected from the API
Represents an API request in Kirara.
This class encapsulates the details of an API request, including the HTTP method,
URL, endpoint, response class, headers, path parameters, request queries, and body.
It provides methods to set these details and compute the final request URL.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ObjectThe body of this API request.protected final StringThe API endpoint to which the request will be sent.protected List<RequestHeader> The headers to be included in this API request.protected final KiraraKirara instance associated with this request.protected final StringThe HTTP method for this request (e.g., "GET", "POST").protected Set<PathParameter> The path parameters to be included in this API request.protected Set<RequestQuery> The request queries to be included in this API request.The class of the expected response type.protected StringThe base URL for the API. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionComputes the request URL for this API request.send()InvokesHttpCore.send(ApiRequest)on the current Kirara instance.<R extends ApiRequest<T>>
RSets the body of this API request.<R extends ApiRequest<T>>
RwithExplicitHeaders(List<RequestHeader> headers) Sets headers for this API requests, discarding any previously set headers.<R extends ApiRequest<T>>
RwithExplicitPathParameters(Set<PathParameter> pathParameters) Sets path parameters for this API request, discarding any previously set path parameters.<R extends ApiRequest<T>>
RwithExplicitRequestQueries(Set<RequestQuery> requestQueries) Sets request queries for this API request, discarding any previously set request queries.<R extends ApiRequest<T>>
RwithHeader(RequestHeader header) Adds a request header to this API request.<R extends ApiRequest<T>>
RwithPathParameter(PathParameter pathParameter) Adds a path parameter to this API request.<R extends ApiRequest<T>>
RwithRequestQuery(RequestQuery requestQuery) Adds a request query to this API request.<R extends ApiRequest<T>>
RSets the URL for this API request.
-
Field Details
-
kirara
Kirara instance associated with this request. -
method
The HTTP method for this request (e.g., "GET", "POST"). -
endpoint
The API endpoint to which the request will be sent. This is a relative path that will be appended to the base URL. If url is null, the default API URL from Kirara will be used. If that will be null as well, the endpoint will be used as the full URL. -
responseClass
The class of the expected response type. This is used to deserialize the response body into the appropriate type. -
url
The base URL for the API. If null, the default API URL from Kirara will be used. If that is also null, the endpoint will be used as the full URL. -
headers
The headers to be included in this API request. This can be null, in which case no headers will be set. -
pathParameters
The path parameters to be included in this API request. This can be null, in which case no path parameters will be set. -
requestQueries
The request queries to be included in this API request. This can be null, in which case no request queries will be set. -
body
The body of this API request. This can be null, in which case no body will be set. It is typically used for requests that require a payload, such as POST or PUT requests.
-
-
Constructor Details
-
ApiRequest
public ApiRequest(Kirara kirara, String method, String url, String endpoint, Class<T> responseClass) Constructs an ApiRequest with the specified parameters.- Parameters:
kirara- the Kirara instance associated with this requestmethod- the HTTP method (e.g., "GET", "POST")url- the base URL for the API, can be null to use the default API URLendpoint- the API endpoint to which the request will be sentresponseClass- the class of the expected response type
-
-
Method Details
-
withUrl
Sets the URL for this API request.- Type Parameters:
R- the type of the request, extending ApiRequest- Parameters:
url- the URL to set for this request. If null, the default API URL from Kirara will be used.- Returns:
- a reference to this ApiRequest, allowing for method chaining.
-
withExplicitHeaders
Sets headers for this API requests, discarding any previously set headers.- Type Parameters:
R- the type of the request, extending ApiRequest- Parameters:
headers- the list of headers to set for this request. If null, no headers will be set.- Returns:
- a reference to this ApiRequest, allowing for method chaining.
-
withExplicitPathParameters
Sets path parameters for this API request, discarding any previously set path parameters.- Type Parameters:
R- the type of the request, extending ApiRequest- Parameters:
pathParameters- the set of path parameters to set for this request. If null, no path parameters will be set.- Returns:
- a reference to this ApiRequest, allowing for method chaining.
-
withExplicitRequestQueries
Sets request queries for this API request, discarding any previously set request queries.- Type Parameters:
R- the type of the request, extending ApiRequest- Parameters:
requestQueries- the set of request queries to set for this request. If null, no request queries will be set.- Returns:
- a reference to this ApiRequest, allowing for method chaining.
-
withHeader
Adds a request header to this API request. If headers were previously set, this method appends the new header to the existing list or creates a new list if none exists.- Type Parameters:
R- the type of the request, extending ApiRequest- Parameters:
header- the request header to add to this API request.- Returns:
- a reference to this ApiRequest, allowing for method chaining.
-
withPathParameter
Adds a path parameter to this API request. If path parameters were previously set, this method appends the new parameter to the existing set or creates a new set if none exists.- Type Parameters:
R- the type of the request, extending ApiRequest- Parameters:
pathParameter- the path parameter to add to this API request.- Returns:
- a reference to this ApiRequest, allowing for method chaining.
-
withRequestQuery
Adds a request query to this API request. If request queries were previously set, this method appends the new query to the existing set or creates a new set if none exists.- Type Parameters:
R- the type of the request, extending ApiRequest- Parameters:
requestQuery- the request query to add to this API request.- Returns:
- a reference to this ApiRequest, allowing for method chaining.
-
withBody
Sets the body of this API request. This method can be used to set the body for requests that require a payload, such as POST or PUT requests.- Type Parameters:
R- the type of the request, extending ApiRequest- Parameters:
body- the body to set for this request. If null, no body will be set.- Returns:
- a reference to this ApiRequest, allowing for method chaining.
-
computeRequestUrl
Computes the request URL for this API request.- Returns:
- the constructed request URL as a String.
-
send
InvokesHttpCore.send(ApiRequest)on the current Kirara instance.- Returns:
- A CompletableFuture that will complete with the response of type T.
-