Class OkHttpFetcher

java.lang.Object
org.moera.lib.jsonrpc.OkHttpFetcher
All Implemented Interfaces:
Function<JsonRpcRequest,JsonRpcResponse>

public class OkHttpFetcher extends Object implements Function<JsonRpcRequest,JsonRpcResponse>
This class is responsible for fetching responses from a remote JSON-RPC server using the OkHttp client.
  • Constructor Details

    • OkHttpFetcher

      public OkHttpFetcher(String url)
      Constructs an instance of OkHttpFetcher with the specified URL.
      Parameters:
      url - the URL of the JSON-RPC server. It must be a valid HTTP or HTTPS URL and is used as the endpoint for all outgoing requests.
  • Method Details

    • apply

      public JsonRpcResponse apply(JsonRpcRequest jsonRpcRequest)
      Processes a JSON-RPC request and fetches the corresponding JSON-RPC response from a remote server. The method uses the OkHttp client to send the request and parse the response.
      Specified by:
      apply in interface Function<JsonRpcRequest,JsonRpcResponse>
      Parameters:
      jsonRpcRequest - the JSON-RPC request to be sent to the remote server
      Returns:
      the JSON-RPC response received from the server
      Throws:
      JsonRpcException - if the response cannot be parsed
      JsonRpcConnectionException - if a network error occurs during the request execution