Class ApiClient

All Implemented Interfaces:
CtxEventListener, ContextHandleAware, HandleAware, Ready, ReadyListener

public final class ApiClient extends AbstractService
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 Details

  • Constructor Details

    • ApiClient

      public ApiClient(NodeId selfNode, boolean isPrimary)
      Create a new client that is running on the specified node.
      Parameters:
      selfNode - the node we're running on
      isPrimary - true if the node we're running on is the primary node
  • Method Details

    • localGet

      public <T> ResponseEnvelope<T> localGet(String url, Class<T> clazz)
      Calls a local controller with a GET request and then deserializes the response to the specified class.
      Parameters:
      url - the URL to call
      clazz - the class to deserialize the response to (optional)
      Returns:
      response envelope containing the status, version, and data
    • localGet

      public <T> ResponseEnvelope<T> localGet(String url, Map<String,Object> headers, Class<T> clazz)
      Calls a local controller with a GET request and then deserializes the response to the specified class.
      Parameters:
      url - the URL to call
      headers - 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

      public <T> ResponseEnvelope<T> localPost(String url, 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 call
      body - the body to post
      clazz - 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 call
      headers - the headers to include in the request (optional)
      body - the body to post
      clazz - 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, 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 call
      body - the body to put
      clazz - 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 call
      headers - the headers to include in the request (optional)
      body - the body to put
      clazz - the class to deserialize the response to (optional)
      Returns:
      response envelope containing the status, version, and data
    • localDelete

      public <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.
      Parameters:
      url - the URL to call
      clazz - the class to deserialize the response to (optional)
      Returns:
      response envelope containing the status, version, and data
    • localDelete

      public <T> ResponseEnvelope<T> localDelete(String url, Map<String,Object> headers, Class<T> clazz)
      Calls a local controller with a DELETE request and then deserializes the response to the specified class.
      Parameters:
      url - the URL to call
      headers - 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)
      Calls a local controller with a POST request and then deserializes the response to the specified class.
      Parameters:
      method - the method to use
      url - the URL to call
      headers - the headers to include in the request (optional)
      body - the body to send
      clazz - the class to deserialize the response to (optional)
      Returns:
      response envelope containing the status, version, and data
    • nodeGet

      public <T> ResponseEnvelope<T> nodeGet(NodeId node, String url, 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
      url - the URL to call
      clazz - the class to deserialize the response to (optional)
      Returns:
      response envelope containing the status, version, and data
    • nodeGet

      public <T> ResponseEnvelope<T> nodeGet(NodeId 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, or null for local
      url - the URL to call
      headers - 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

      public <T> ResponseEnvelope<T> nodePost(NodeId node, String url, 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
      url - the URL to call
      body - the body to post
      clazz - the class to deserialize the response to (optional)
      Returns:
      response envelope containing the status, version, and data
    • nodePost

      public <T> ResponseEnvelope<T> nodePost(NodeId 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
      url - the URL to call
      headers - the headers to include in the request (optional)
      body - the body to post
      clazz - the class to deserialize the response to (optional)
      Returns:
      response envelope containing the status, version, and data
    • nodePut

      public <T> ResponseEnvelope<T> nodePut(NodeId node, String url, 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
      url - the URL to call
      body - the body to put
      clazz - the class to deserialize the response to (optional)
      Returns:
      response envelope containing the status, version, and data
    • nodePut

      public <T> ResponseEnvelope<T> nodePut(NodeId 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
      url - the URL to call
      headers - the headers to include in the request (optional)
      body - the body to put
      clazz - the class to deserialize the response to (optional)
      Returns:
      response envelope containing the status, version, and data
    • nodeDelete

      public <T> ResponseEnvelope<T> nodeDelete(NodeId 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.
      Parameters:
      node - the node to call
      url - the URL to call
      clazz - the class to deserialize the response to (optional)
      Returns:
      response envelope containing the status, version, and data
    • nodeDelete

      public <T> ResponseEnvelope<T> nodeDelete(NodeId 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
      url - the URL to call
      headers - 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(NodeId 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
      method - the method to use
      url - the URL to call
      headers - the headers to include in the request (optional)
      body - the body to send
      clazz - the class to deserialize the response to (optional)
      timeout - optional timeout (0 for default)
      Returns:
      response envelope containing the status, version, and data
    • aliasGet

      public <T> ResponseEnvelope<T> aliasGet(String alias, String url, Class<T> clazz)
      Calls a controller on the node with the specified alias with a GET request and then deserializes the response to the specified class.
      Parameters:
      alias - the alias of the node to call
      url - the URL to call
      clazz - the class to deserialize the response to (optional)
      Returns:
      response envelope containing the status, version, and data
    • aliasGet

      public <T> ResponseEnvelope<T> aliasGet(String alias, String url, Map<String,Object> headers, Class<T> clazz)
      Calls a controller on the node with the specified alias with a GET request and then deserializes the response to the specified class.
      Parameters:
      alias - the alias of the node to call
      url - the URL to call
      headers - 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
    • aliasPost

      public <T> ResponseEnvelope<T> aliasPost(String alias, String url, Object body, Class<T> clazz)
      Calls a controller on the node with the specified alias with a POST request and then deserializes the response to the specified class.
      Parameters:
      alias - the alias of the node to call
      url - the URL to call
      body - the body to post
      clazz - the class to deserialize the response to (optional)
      Returns:
      response envelope containing the status, version, and data
    • aliasPost

      public <T> ResponseEnvelope<T> aliasPost(String alias, String url, Map<String,Object> headers, Object body, Class<T> clazz)
      Calls a controller on the node with the specified alias with a POST request and then deserializes the response to the specified class.
      Parameters:
      alias - the alias of the node to call
      url - the URL to call
      headers - the headers to include in the request (optional)
      body - the body to post
      clazz - the class to deserialize the response to (optional)
      Returns:
      response envelope containing the status, version, and data
    • addrPut

      public <T> ResponseEnvelope<T> addrPut(String alias, String url, Object body, Class<T> clazz)
      Calls a controller on the node with the specified alias with a PUT request and then deserializes the response to the specified class.
      Parameters:
      alias - the alias of the node to call
      url - the URL to call
      body - the body to put
      clazz - the class to deserialize the response to (optional)
      Returns:
      response envelope containing the status, version, and data
    • aliasPut

      public <T> ResponseEnvelope<T> aliasPut(String alias, String url, Map<String,Object> headers, Object body, Class<T> clazz)
      Calls a controller on the node with the specified alias with a PUT request and then deserializes the response to the specified class.
      Parameters:
      alias - the alias of the node to call
      url - the URL to call
      headers - the headers to include in the request (optional)
      body - the body to put
      clazz - the class to deserialize the response to (optional)
      Returns:
      response envelope containing the status, version, and data
    • aliasDelete

      public <T> ResponseEnvelope<T> aliasDelete(String alias, String url, Class<T> clazz)
      Calls a controller on the node with the specified alias with a DELETE request and then deserializes the response to the specified class.
      Parameters:
      alias - the alias of the node to call
      url - the URL to call
      clazz - the class to deserialize the response to (optional)
      Returns:
      response envelope containing the status, version, and data
    • aliasDelete

      public <T> ResponseEnvelope<T> aliasDelete(String alias, String url, Map<String,Object> headers, Class<T> clazz)
      Calls a controller on the node with the specified alias with a DELETE request and then deserializes the response to the specified class.
      Parameters:
      alias - the alias of the node to call
      url - the URL to call
      headers - 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
    • aliasApi

      public <T> ResponseEnvelope<T> aliasApi(String alias, RequestMethod method, String url, Map<String,Object> headers, Object body, Class<T> clazz, int timeout)
      Calls a controller on the node with the specified alias with a POST request and then deserializes the response to the specified class.
      Parameters:
      alias - the alias of the node to call
      method - the method to use
      url - the URL to call
      headers - the headers to include in the request (optional)
      body - the body to send
      clazz - the class to deserialize the response to (optional)
      timeout - optional timeout (0 for default)
      Returns:
      response envelope containing the status, version, and data
    • primaryGet

      public <T> ResponseEnvelope<T> primaryGet(String url, Class<T> clazz)
      Calls a controller on the primary node with a GET request and then deserializes the response to the specified class.
      Parameters:
      url - the URL to call
      clazz - the class to deserialize the response to (optional)
      Returns:
      response envelope containing the status, version, and data
    • primaryGet

      public <T> ResponseEnvelope<T> primaryGet(String url, Map<String,Object> headers, Class<T> clazz)
      Calls a controller on the primary node with a GET request and then deserializes the response to the specified class.
      Parameters:
      url - the URL to call
      headers - 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
    • primaryPost

      public <T> ResponseEnvelope<T> primaryPost(String url, Object body, Class<T> clazz)
      Calls a controller on the primary node with a POST request and then deserializes the response to the specified class.
      Parameters:
      url - the URL to call
      body - the body to post
      clazz - the class to deserialize the response to (optional)
      Returns:
      response envelope containing the status, version, and data
    • primaryPost

      public <T> ResponseEnvelope<T> primaryPost(String url, Map<String,Object> headers, Object body, Class<T> clazz)
      Calls a controller on the primary node with a POST request and then deserializes the response to the specified class.
      Parameters:
      url - the URL to call
      headers - the headers to include in the request (optional)
      body - the body to post
      clazz - the class to deserialize the response to (optional)
      Returns:
      response envelope containing the status, version, and data
    • primaryPut

      public <T> ResponseEnvelope<T> primaryPut(String url, Object body, Class<T> clazz)
      Calls a controller on the primary node with a PUT request and then deserializes the response to the specified class.
      Parameters:
      url - the URL to call
      body - the body to put
      clazz - the class to deserialize the response to (optional)
      Returns:
      response envelope containing the status, version, and data
    • primaryPut

      public <T> ResponseEnvelope<T> primaryPut(String url, Map<String,Object> headers, Object body, Class<T> clazz)
      Calls a controller on the primary node with a PUT request and then deserializes the response to the specified class.
      Parameters:
      url - the URL to call
      headers - the headers to include in the request (optional)
      body - the body to put
      clazz - the class to deserialize the response to (optional)
      Returns:
      response envelope containing the status, version, and data
    • primaryDelete

      public <T> ResponseEnvelope<T> primaryDelete(String url, Class<T> clazz)
      Calls a controller on the primary node with a DELETE request and then deserializes the response to the specified class.
      Parameters:
      url - the URL to call
      clazz - the class to deserialize the response to (optional)
      Returns:
      response envelope containing the status, version, and data
    • primaryDelete

      public <T> ResponseEnvelope<T> primaryDelete(String url, Object body, Class<T> clazz)
      Calls a controller on the primary node with a DELETE request and then deserializes the response to the specified class.
      Parameters:
      url - the URL to call
      body - the body to delete
      clazz - the class to deserialize the response to (optional)
      Returns:
      response envelope containing the status, version, and data
    • primaryDelete

      public <T> ResponseEnvelope<T> primaryDelete(String url, Map<String,Object> headers, Class<T> clazz)
      Calls a controller on the primary node with a DELETE request and then deserializes the response to the specified class.
      Parameters:
      url - the URL to call
      headers - 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
    • primaryDelete

      public <T> ResponseEnvelope<T> primaryDelete(String url, Map<String,Object> headers, Object body, Class<T> clazz)
      Calls a controller on the primary node with a DELETE request and then deserializes the response to the specified class.
      Parameters:
      url - the URL to call
      headers - the headers to include in the request (optional)
      body - the body to delete
      clazz - the class to deserialize the response to (optional)
      Returns:
      response envelope containing the status, version, and data
    • primaryApi

      public <T> ResponseEnvelope<T> primaryApi(RequestMethod method, String url, Map<String,Object> headers, Object body, Class<T> clazz, int timeout)
      Calls a controller on the primary node with a POST request and then deserializes the response to the specified class.
      Parameters:
      method - the method to use
      url - the URL to call
      headers - the headers to include in the request (optional)
      body - the body to send
      clazz - the class to deserialize the response to (optional)
      timeout - optional timeout (0 for default)
      Returns:
      response envelope containing the status, version, and data
    • api

      public <T> ResponseEnvelope<T> api(ApiRequest<T> request)
      Performs an API call using the settings in the request object.
      Parameters:
      request - the request object
      Returns:
      response envelope containing the status, version, and data