Class ApiDecisionLoader

java.lang.Object
io.gorules.zen.loader.ApiDecisionLoader
All Implemented Interfaces:
DecisionLoader

public class ApiDecisionLoader extends Object implements DecisionLoader
Decision loader that fetches decisions from an HTTP API. Supports flexible header configuration, caching, and automatic retries.

 ApiLoaderConfig config = ApiLoaderConfig.builder("https://api.example.com/decisions")
     .header("Authorization", "Bearer token123")
     .header("X-Custom-Header", "value")
     .timeout(Duration.ofSeconds(30))
     .caching(true)
     .build();

 ApiDecisionLoader loader = new ApiDecisionLoader(config);

 // Load decision from: GET https://api.example.com/decisions/pricing.json
 CompletableFuture<JsonBuffer> decision = loader.load("pricing.json");
 
  • Constructor Details

    • ApiDecisionLoader

      public ApiDecisionLoader(ApiLoaderConfig config)
      Create a new ApiDecisionLoader with the given configuration.
      Parameters:
      config - API loader configuration
  • Method Details

    • load

      public CompletableFuture<io.gorules.zen_engine.JsonBuffer> load(String key)
      Description copied from interface: DecisionLoader
      Load a decision by its key.
      Specified by:
      load in interface DecisionLoader
      Parameters:
      key - Decision key/filename
      Returns:
      CompletableFuture with decision content as JsonBuffer
    • clearCache

      public void clearCache()
      Clear the cache.
    • evict

      public void evict(String key)
      Evict a specific decision from cache.
      Parameters:
      key - Decision key
    • isCached

      public boolean isCached(String key)
      Check if a decision is cached.
      Parameters:
      key - Decision key
      Returns:
      true if cached
    • getConfig

      public ApiLoaderConfig getConfig()
      Get the configuration for this loader.
      Returns:
      ApiLoaderConfig