Java.libraries.resttemplate.BaseApi.mustache Maven / Gradle / Ivy
package {{invokerPackage}};
import org.springframework.web.client.RestClientException;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
{{>generatedAnnotation}}
public abstract class BaseApi {
protected ApiClient apiClient;
public BaseApi() {
this(new ApiClient());
}
public BaseApi(ApiClient apiClient) {
this.apiClient = apiClient;
}
public ApiClient getApiClient() {
return apiClient;
}
public void setApiClient(ApiClient apiClient) {
this.apiClient = apiClient;
}
/**
* Directly invoke the API for the given URL. Useful if the API returns direct links/URLs for subsequent requests.
* @param url The URL for the request, either full URL or only the path.
* @param method The HTTP method for the request.
* @return ResponseEntity<Void>
* @throws RestClientException if an error occurs while attempting to invoke the API
*/
public ResponseEntity invokeAPI(String url, HttpMethod method) throws RestClientException {
return invokeAPI(url, method, null, new ParameterizedTypeReference() {});
}
/**
* Directly invoke the API for the given URL. Useful if the API returns direct links/URLs for subsequent requests.
* @param url The URL for the request, either full URL or only the path.
* @param method The HTTP method for the request.
* @param request The request object.
* @return ResponseEntity<Void>
* @throws RestClientException if an error occurs while attempting to invoke the API
*/
public ResponseEntity invokeAPI(String url, HttpMethod method, Object request) throws RestClientException {
return invokeAPI(url, method, request, new ParameterizedTypeReference() {});
}
/**
* Directly invoke the API for the given URL. Useful if the API returns direct links/URLs for subsequent requests.
* @param url The URL for the request, either full URL or only the path.
* @param method The HTTP method for the request.
* @param returnType The return type.
* @return ResponseEntity in the specified type.
* @throws RestClientException if an error occurs while attempting to invoke the API
*/
public ResponseEntity invokeAPI(String url, HttpMethod method, ParameterizedTypeReference returnType) throws RestClientException {
return invokeAPI(url, method, null, returnType);
}
/**
* Directly invoke the API for the given URL. Useful if the API returns direct links/URLs for subsequent requests.
* @param url The URL for the request, either full URL or only the path.
* @param method The HTTP method for the request.
* @param request The request object.
* @param returnType The return type.
* @return ResponseEntity in the specified type.
* @throws RestClientException if an error occurs while attempting to invoke the API
*/
public abstract ResponseEntity invokeAPI(String url, HttpMethod method, Object request, ParameterizedTypeReference returnType) throws RestClientException;
}