Package com.tccc.kos.commons.web.api
Class ApiClient
java.lang.Object
com.tccc.kos.commons.util.ready.ReadyBean
com.tccc.kos.commons.core.service.AbstractService
com.tccc.kos.commons.web.api.ApiClient
- All Implemented Interfaces:
CtxEventListener
,ContextHandleAware
,HandleAware
,Ready
,ReadyListener
System component used to interact with applications running on nodes within a kOS cluster.
Examples
Local GET
public class MyClass {
@Autowired
private ApiClient apiClient;
public void someMethod() {
String url = "https://mydomain.name/path/to/resource";
ResponseEnvelope<SomeData> response = apiClient.localGet(url, SomeData.class);
}
}
Remove POST
public class MyClass {
@Autowired
private ApiClient apiClient;
public void someMethod() {
String node = "Node7";
String url = "https://mydomain.name/path/to/resource";
OutData outData = new OutData("abc", 123);
ResponseEnvelope<InData> response = apiClient.nodePost(node, url, outData, InData.class);
}
}
- Since:
- 1.0
- Version:
- 2023-03-06
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescription<T> ResponseEnvelope<T>
api
(ApiRequest<T> request) Performs an API call using the settings in therequest
object.<T> ResponseEnvelope<T>
localApi
(RequestMethod method, String url, Map<String, Object> headers, Object body, Class<T> clazz, int timeout) Calls a local controller with a POST request and then deserializes the response to the specified class.<T> ResponseEnvelope<T>
localDelete
(String url, Class<T> clazz) Calls a local controller with a DELETE request and then deserializes the response to the specified class.<T> ResponseEnvelope<T>
Calls a local controller with a DELETE request and then deserializes the response to the specified class.<T> ResponseEnvelope<T>
Calls a local controller with a GET request and then deserializes the response to the specified class.<T> ResponseEnvelope<T>
Calls a local controller with a GET request and then deserializes the response to the specified class.<T> ResponseEnvelope<T>
Calls a local controller with a POST request and then deserializes the response to the specified class.<T> ResponseEnvelope<T>
Calls a local controller with a POST request and then deserializes the response to the specified class.<T> ResponseEnvelope<T>
Calls a local controller with a PUT request and then deserializes the response to the specified class.<T> ResponseEnvelope<T>
Calls a local controller with a PUT request and then deserializes the response to the specified class.<T> ResponseEnvelope<T>
nodeApi
(String node, RequestMethod method, String url, Map<String, Object> headers, Object body, Class<T> clazz, int timeout) Calls a controller on the specified node with a POST request and then deserializes the response to the specified class.<T> ResponseEnvelope<T>
nodeDelete
(String node, String url, Class<T> clazz) Calls a controller on the specified node with a DELETE request and then deserializes the response to the specified class.<T> ResponseEnvelope<T>
Calls a controller on the specified node with a DELETE request and then deserializes the response to the specified class.<T> ResponseEnvelope<T>
Calls a controller on the specified node with a GET request and then deserializes the response to the specified class.<T> ResponseEnvelope<T>
Calls a controller on the specified node with a GET request and then deserializes the response to the specified class.<T> ResponseEnvelope<T>
Calls a controller on the specified node with a POST request and then deserializes the response to the specified class.<T> ResponseEnvelope<T>
Calls a controller on the specified node with a POST request and then deserializes the response to the specified class.<T> ResponseEnvelope<T>
Calls a controller on the specified node with a PUT request and then deserializes the response to the specified class.<T> ResponseEnvelope<T>
Calls a controller on the specified node with a PUT request and then deserializes the response to the specified class.Methods inherited from class com.tccc.kos.commons.core.service.AbstractService
getHandle, getHandlePrefix
Methods inherited from class com.tccc.kos.commons.util.ready.ReadyBean
getReady, onBeanReady, onDependenciesReady
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.tccc.kos.commons.core.context.CtxEventListener
onCtxAutowiringCompleted, onCtxDestroyed, onCtxPhaseCompleted
Methods inherited from interface com.tccc.kos.commons.core.service.handle.HandleAware
addHandleChild, getName, getPath
Methods inherited from interface com.tccc.kos.commons.util.ready.ReadyListener
onDependenciesGroupReady
-
Field Details
-
DEFAULT_TIMEOUT
public static final int DEFAULT_TIMEOUT- See Also:
-
-
Method Details
-
localGet
Calls a local controller with a GET request and then deserializes the response to the specified class.- Parameters:
url
- the URL to callclazz
- the class to deserialize the response to (optional)- Returns:
- response envelope containing the status, version, and data
-
localGet
Calls a local controller with a GET request and then deserializes the response to the specified class.- Parameters:
url
- the URL to callheaders
- the headers to include in the request (optional)clazz
- the class to deserialize the response to (optional)- Returns:
- response envelope containing the status, version, and data
-
localPost
Calls a local controller with a POST request and then deserializes the response to the specified class.- Parameters:
url
- the URL to callbody
- the body to postclazz
- the class to deserialize the response to (optional)- Returns:
- response envelope containing the status, version, and data
-
localPost
public <T> ResponseEnvelope<T> localPost(String url, Map<String, Object> headers, Object body, Class<T> clazz) Calls a local controller with a POST request and then deserializes the response to the specified class.- Parameters:
url
- the URL to callheaders
- the headers to include in the request (optional)body
- the body to postclazz
- the class to deserialize the response to (optional)- Returns:
- response envelope containing the status, version, and data
-
localPut
Calls a local controller with a PUT request and then deserializes the response to the specified class.- Parameters:
url
- the URL to callbody
- the body to putclazz
- the class to deserialize the response to (optional)- Returns:
- response envelope containing the status, version, and data
-
localPut
public <T> ResponseEnvelope<T> localPut(String url, Map<String, Object> headers, Object body, Class<T> clazz) Calls a local controller with a PUT request and then deserializes the response to the specified class.- Parameters:
url
- the URL to callheaders
- the headers to include in the request (optional)body
- the body to putclazz
- the class to deserialize the response to (optional)- Returns:
- response envelope containing the status, version, and data
-
localDelete
Calls a local controller with a DELETE request and then deserializes the response to the specified class.- Parameters:
url
- the URL to callclazz
- the class to deserialize the response to (optional)- Returns:
- response envelope containing the status, version, and data
-
localDelete
Calls a local controller with a DELETE request and then deserializes the response to the specified class.- Parameters:
url
- the URL to callheaders
- the headers to include in the request (optional)clazz
- the class to deserialize the response to (optional)- Returns:
- response envelope containing the status, version, and data
-
localApi
public <T> ResponseEnvelope<T> localApi(RequestMethod method, String url, Map<String, Object> headers, Object body, Class<T> clazz, int timeout) Calls a local controller with a POST request and then deserializes the response to the specified class.- Parameters:
method
- the method to useurl
- the URL to callheaders
- the headers to include in the request (optional)body
- the body to sendclazz
- the class to deserialize the response to (optional)timeout
- optional timeout (0 for default)- Returns:
- response envelope containing the status, version, and data
-
nodeGet
Calls a controller on the specified node with a GET request and then deserializes the response to the specified class.- Parameters:
node
- the node to call, ornull
for localurl
- the URL to callclazz
- the class to deserialize the response to (optional)- Returns:
- response envelope containing the status, version, and data
-
nodeGet
public <T> ResponseEnvelope<T> nodeGet(String node, String url, Map<String, Object> headers, Class<T> clazz) Calls a controller on the specified node with a GET request and then deserializes the response to the specified class.- Parameters:
node
- the node to call, ornull
for localurl
- the URL to callheaders
- the headers to include in the request (optional)clazz
- the class to deserialize the response to (optional)- Returns:
- response envelope containing the status, version, and data
-
nodePost
Calls a controller on the specified node with a POST request and then deserializes the response to the specified class.- Parameters:
node
- the node to call, ornull
for localurl
- the URL to callbody
- the body to postclazz
- the class to deserialize the response to (optional)- Returns:
- response envelope containing the status, version, and data
-
nodePost
public <T> ResponseEnvelope<T> nodePost(String node, String url, Map<String, Object> headers, Object body, Class<T> clazz) Calls a controller on the specified node with a POST request and then deserializes the response to the specified class.- Parameters:
node
- the node to call, ornull
for localurl
- the URL to callheaders
- the headers to include in the request (optional)body
- the body to postclazz
- the class to deserialize the response to (optional)- Returns:
- response envelope containing the status, version, and data
-
nodePut
Calls a controller on the specified node with a PUT request and then deserializes the response to the specified class.- Parameters:
node
- the node to call, ornull
for localurl
- the URL to callbody
- the body to putclazz
- the class to deserialize the response to (optional)- Returns:
- response envelope containing the status, version, and data
-
nodePut
public <T> ResponseEnvelope<T> nodePut(String node, String url, Map<String, Object> headers, Object body, Class<T> clazz) Calls a controller on the specified node with a PUT request and then deserializes the response to the specified class.- Parameters:
node
- the node to call, ornull
for localurl
- the URL to callheaders
- the headers to include in the request (optional)body
- the body to putclazz
- the class to deserialize the response to (optional)- Returns:
- response envelope containing the status, version, and data
-
nodeDelete
Calls a controller on the specified node with a DELETE request and then deserializes the response to the specified class.- Parameters:
node
- the node to call, ornull
for localurl
- the URL to callclazz
- the class to deserialize the response to (optional)- Returns:
- response envelope containing the status, version, and data
-
nodeDelete
public <T> ResponseEnvelope<T> nodeDelete(String node, String url, Map<String, Object> headers, Class<T> clazz) Calls a controller on the specified node with a DELETE request and then deserializes the response to the specified class.- Parameters:
node
- the node to call, ornull
for localurl
- the URL to callheaders
- the headers to include in the request (optional)clazz
- the class to deserialize the response to (optional)- Returns:
- response envelope containing the status, version, and data
-
nodeApi
public <T> ResponseEnvelope<T> nodeApi(String node, RequestMethod method, String url, Map<String, Object> headers, Object body, Class<T> clazz, int timeout) Calls a controller on the specified node with a POST request and then deserializes the response to the specified class.- Parameters:
node
- the node to call, ornull
for localmethod
- the method to useurl
- the URL to callheaders
- the headers to include in the request (optional)body
- the body to sendclazz
- the class to deserialize the response to (optional)timeout
- optional timeout (0 for default)- Returns:
- response envelope containing the status, version, and data
-
api
Performs an API call using the settings in therequest
object.- Parameters:
request
- the request object- Returns:
- response envelope containing the status, version, and data
-