Package org.moera.lib.node
Class NodeApiClient
java.lang.Object
org.moera.lib.node.NodeApiClient
- Direct Known Subclasses:
MoeraNode
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 ClassesModifier and TypeClassDescriptionstatic interface
The interface provides a single method to process aResponseBody
, allowing custom handling of API responses received from a node. -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor for theNodeApiClient
class.NodeApiClient
(String nodeUrl) Constructs a new instance of theNodeApiClient
class and initializes it with the given node URL. -
Method Summary
Modifier and TypeMethodDescriptionvoid
auth()
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
Set carte for authentication.void
carteSource
(CarteSource carteSource) Set a source of cartes for authentication.protected String
commaSeparatedFlags
(QueryParam... flags) getRoot()
API endpoint URL of the node.static String
Convert partial node URL to a standardized form.void
noAuth()
Switch off authentication for the following requests.void
Set node URL.void
rootSecret
(String secret) Set root secret for authentication.void
Set admin token for authentication.protected String
-
Constructor Details
-
NodeApiClient
public NodeApiClient()Default constructor for theNodeApiClient
class. -
NodeApiClient
Constructs a new instance of theNodeApiClient
class and initializes it with the given node URL.- Parameters:
nodeUrl
- the URL of the node to connect to
-
-
Method Details
-
getRoot
API endpoint URL of the node. -
moeraRoot
Convert partial node URL to a standardized form.- Parameters:
url
- partial URL- Returns:
- standard URL
-
nodeUrl
Set node URL.- Parameters:
url
- the URL
-
rootSecret
Set root secret for authentication.- Parameters:
secret
- the secret
-
token
Set admin token for authentication.- Parameters:
token
- the token
-
carte
Set carte for authentication.- Parameters:
carte
- the carte
-
carteSource
Set a source of cartes for authentication.- Parameters:
carteSource
- the source of cartes
-
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 URLparams
- an array of query parameters to be included in the API request; may benull
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 benull
for methods likeGET
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 URLparams
- an array of query parameters to be included in the API request; may benull
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 benull
for methods likeGET
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 URLparams
- an array of query parameters to be included in the API request, may benull
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 benull
for methods likeGET
contentType
- the MIME type of the request bodyresultClass
- 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 URLparams
- an array of query parameters to be included in the API request, may benull
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 benull
for methods likeGET
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
- Throws:
MoeraNodeException
-
commaSeparatedFlags
-