Package dev.mayuna.simpleapi
Class ApiRequestBuilder<T>
java.lang.Object
dev.mayuna.simpleapi.ApiRequestBuilder<T>
- Type Parameters:
T- The type of the response.
A builder for
ApiRequest.-
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds theApiRequest.static <T> ApiRequestBuilder<T>ofResponse(WrappedApi wrappedApi, Class<T> responseClass) withBodyHandler(HttpResponse.BodyHandler<?> bodyHandler) Sets theHttpResponse.BodyHandlerof the request.withBodyPublisher(HttpRequest.BodyPublisher bodyPublisher) Sets theHttpRequest.BodyPublisherof the request.withEndpoint(@NonNull String endpoint) Sets the endpoint of the request.withPathParameter(@NonNull PathParameter pathParameter) Adds aPathParameterto the request.withPathParameters(@NonNull PathParameter pathParameter, PathParameter... pathParameters) Adds multiplePathParameters to the request.withRequestHeader(@NonNull RequestHeader requestHeader) Adds aRequestHeaderto the request.withRequestHeaders(@NonNull RequestHeader requestHeader, RequestHeader... requestHeaders) Adds multipleRequestHeaders to the request.withRequestMethod(@NonNull RequestMethod requestMethod) Sets the request method of the request.
Pro-tip: You can use pre-defined instances ofRequestMethodlikeRequestMethod.GET.withRequestMethod(@NonNull String requestMethod) withRequestQueries(@NonNull RequestQuery requestQuery, RequestQuery... requestQueries) Adds multipleRequestQuerys to the request.withRequestQuery(@NonNull RequestQuery requestQuery) Adds aRequestQueryto the request.Sets the url of the request.
-
Method Details
-
ofResponse
- Type Parameters:
T- The type of the response.- Parameters:
wrappedApi- TheWrappedApito use.responseClass- TheClassof the response.- Returns:
- The created
ApiRequestBuilder.
-
withUrl
Sets the url of the request. This will override the default url of theWrappedApi.- Parameters:
url- The url to set. Should not contain a trailing slash.- Returns:
- The
ApiRequestBuilderinstance.
-
withEndpoint
Sets the endpoint of the request.- Parameters:
endpoint- The endpoint to set. Should contain a leading slash.- Returns:
- The
ApiRequestBuilderinstance.
-
withRequestMethod
Sets the request method of the request.
Pro-tip: You can use pre-defined instances ofRequestMethodlikeRequestMethod.GET.- Parameters:
requestMethod- The request method to set.- Returns:
- The
ApiRequestBuilderinstance.
-
withRequestMethod
-
withPathParameter
Adds aPathParameterto the request.- Parameters:
pathParameter- ThePathParameterto add.- Returns:
- The
ApiRequestBuilderinstance.
-
withPathParameters
public ApiRequestBuilder<T> withPathParameters(@NonNull @NonNull PathParameter pathParameter, PathParameter... pathParameters) Adds multiplePathParameters to the request.- Parameters:
pathParameter- The firstPathParameterto add.pathParameters- The otherPathParameters to add.- Returns:
- The
ApiRequestBuilderinstance.
-
withRequestQuery
Adds aRequestQueryto the request.- Parameters:
requestQuery- TheRequestQueryto add.- Returns:
- The
ApiRequestBuilderinstance.
-
withRequestQueries
public ApiRequestBuilder<T> withRequestQueries(@NonNull @NonNull RequestQuery requestQuery, RequestQuery... requestQueries) Adds multipleRequestQuerys to the request.- Parameters:
requestQuery- The firstRequestQueryto add.requestQueries- The otherRequestQuerys to add.- Returns:
- The
ApiRequestBuilderinstance.
-
withRequestHeader
Adds aRequestHeaderto the request.- Parameters:
requestHeader- TheRequestHeaderto add.- Returns:
- The
ApiRequestBuilderinstance.
-
withRequestHeaders
public ApiRequestBuilder<T> withRequestHeaders(@NonNull @NonNull RequestHeader requestHeader, RequestHeader... requestHeaders) Adds multipleRequestHeaders to the request.- Parameters:
requestHeader- The firstRequestHeaderto add.requestHeaders- The otherRequestHeaders to add.- Returns:
- The
ApiRequestBuilderinstance.
-
withBodyPublisher
Sets theHttpRequest.BodyPublisherof the request.- Parameters:
bodyPublisher- TheHttpRequest.BodyPublisherto set.- Returns:
- The
ApiRequestBuilderinstance.
-
withBodyHandler
Sets theHttpResponse.BodyHandlerof the request.- Parameters:
bodyHandler- TheHttpResponse.BodyHandlerto set.- Returns:
- The
ApiRequestBuilderinstance.
-
build
Builds theApiRequest.- Returns:
- The built
ApiRequest.
-