Class NodeApiClient

java.lang.Object
org.moera.lib.node.NodeApiClient
Direct Known Subclasses:
MoeraNode

public class NodeApiClient extends Object
This class implements basic REST API operations that allow applications to call Moera Node API.

This class is not thread-safe.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    The interface provides a single method to process a ResponseBody, allowing custom handling of API responses received from a node.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor for the NodeApiClient class.
    Constructs a new instance of the NodeApiClient class and initializes it with the given node URL.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Select carte authentication for the following requests.
    void
    Select admin token authentication for the following requests.
    void
    authMethod(NodeAuth authMethod)
    Select authentication method for the following requests.
    void
    Select root admin secret authentication for the following requests.
    <T> T
    call(String location, QueryParam[] params, String method, Object body, com.fasterxml.jackson.core.type.TypeReference<T> resultClass)
    Executes a request to the node API with the specified parameters and parses the JSON response into the specified result type.
    void
    call(String location, QueryParam[] params, String method, Object body, NodeApiClient.ResponseConsumer responseConsumer)
    Executes a request to the node API with the specified parameters.
    <T> T
    call(String location, QueryParam[] params, String method, Path body, String contentType, com.fasterxml.jackson.core.type.TypeReference<T> resultClass)
    Executes a request to the node API with the specified parameters and parses the JSON response into the specified result type.
    void
    call(String location, QueryParam[] params, String method, okhttp3.RequestBody requestBody, NodeApiClient.ResponseConsumer responseConsumer)
    Executes a request to the node API with the specified parameters.
    void
    carte(String carte)
    Set carte for authentication.
    void
    carteSource(CarteSource carteSource)
    Set a source of cartes for authentication.
    protected String
     
    API endpoint URL of the node.
    static String
    Convert partial node URL to a standardized form.
    void
    Switch off authentication for the following requests.
    void
    Set node URL.
    void
    Set root secret for authentication.
    void
    token(String token)
    Set admin token for authentication.
    protected String
    ue(Object value)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • NodeApiClient

      public NodeApiClient()
      Default constructor for the NodeApiClient class.
    • NodeApiClient

      public NodeApiClient(String nodeUrl)
      Constructs a new instance of the NodeApiClient class and initializes it with the given node URL.
      Parameters:
      nodeUrl - the URL of the node to connect to
  • Method Details

    • getRoot

      public String getRoot()
      API endpoint URL of the node.
    • moeraRoot

      public static String moeraRoot(String url)
      Convert partial node URL to a standardized form.
      Parameters:
      url - partial URL
      Returns:
      standard URL
    • nodeUrl

      public void nodeUrl(String url)
      Set node URL.
      Parameters:
      url - the URL
    • rootSecret

      public void rootSecret(String secret)
      Set root secret for authentication.
      Parameters:
      secret - the secret
    • token

      public void token(String token)
      Set admin token for authentication.
      Parameters:
      token - the token
    • carte

      public void carte(String carte)
      Set carte for authentication.
      Parameters:
      carte - the carte
    • carteSource

      public void carteSource(CarteSource carteSource)
      Set a source of cartes for authentication.
      Parameters:
      carteSource - the source of cartes
    • authMethod

      public void authMethod(NodeAuth authMethod)
      Select authentication method for the following requests.
      Parameters:
      authMethod - the authentication method
    • noAuth

      public void noAuth()
      Switch off authentication for the following requests.
    • auth

      public void auth()
      Select carte authentication for the following requests.
    • authAdmin

      public void authAdmin()
      Select admin token authentication for the following requests.
    • authRootAdmin

      public void authRootAdmin()
      Select root admin secret authentication for the following requests.
    • call

      public <T> T call(String location, QueryParam[] params, String method, Object body, com.fasterxml.jackson.core.type.TypeReference<T> resultClass) throws MoeraNodeException
      Executes a request to the node API with the specified parameters and parses the JSON response into the specified result type.
      Type Parameters:
      T - the type of the expected response object
      Parameters:
      location - the endpoint location of the API call, relative to the node's root URL
      params - an array of query parameters to be included in the API request; may be null
      method - the HTTP method to use for the request (e.g., GET, POST, DELETE)
      body - an object representing the request body to include in the API request, the object is converted to JSON before sending; can be null for methods like GET
      resultClass - the type reference of the expected response object
      Returns:
      the parsed response object of type T
      Throws:
      MoeraNodeException - if an error occurs during request processing or response handling
    • call

      public void call(String location, QueryParam[] params, String method, Object body, NodeApiClient.ResponseConsumer responseConsumer) throws MoeraNodeException
      Executes a request to the node API with the specified parameters.
      Parameters:
      location - the endpoint location of the API call, relative to the node's root URL
      params - an array of query parameters to be included in the API request; may be null
      method - the HTTP method to use for the request (e.g., GET, POST, DELETE)
      body - an object representing the request body to include in the API request, the object is converted to JSON before sending; can be null for methods like GET
      responseConsumer - a consumer that processes the response body received from the node
      Throws:
      MoeraNodeException - if an error occurs during request processing or response handling
    • call

      public <T> T call(String location, QueryParam[] params, String method, Path body, String contentType, com.fasterxml.jackson.core.type.TypeReference<T> resultClass) throws MoeraNodeException
      Executes a request to the node API with the specified parameters and parses the JSON response into the specified result type.
      Type Parameters:
      T - the type of the expected response object
      Parameters:
      location - the endpoint location of the API call, relative to the node's root URL
      params - an array of query parameters to be included in the API request, may be null
      method - the HTTP method to use for the request (e.g., GET, POST, DELETE)
      body - the file path for the request body to include in the API request; can be null for methods like GET
      contentType - the MIME type of the request body
      resultClass - the type reference of the expected response object
      Returns:
      the parsed response object of type T
      Throws:
      MoeraNodeException - if an error occurs during request processing or response handling
    • call

      public void call(String location, QueryParam[] params, String method, okhttp3.RequestBody requestBody, NodeApiClient.ResponseConsumer responseConsumer) throws MoeraNodeException
      Executes a request to the node API with the specified parameters.
      Parameters:
      location - the endpoint location of the API call, relative to the node's root URL
      params - an array of query parameters to be included in the API request, may be null
      method - the HTTP method to use for the request (e.g., GET, POST, DELETE)
      requestBody - the request body to include in the API request; can be null for methods like GET
      responseConsumer - a consumer that processes the response body received from the node
      Throws:
      MoeraNodeException - if an error occurs during request processing or response handling
    • ue

      protected String ue(Object value) throws MoeraNodeException
      Throws:
      MoeraNodeException
    • commaSeparatedFlags

      protected String commaSeparatedFlags(QueryParam... flags)