Class ApiProxy

java.lang.Object
net.targetr.rc.util.ApiProxy

public class ApiProxy extends Object
Proxies HTTP requests to external APIs, injecting necessary API keys. Handles predefined targets, reading configured keys from api-keys.properties. The Open-Meteo forecast target does not require a key.
  • Constructor Details

    • ApiProxy

      public ApiProxy(ProxyCache cache)
      Constructs a new ApiProxy using the supplied response cache.
      Parameters:
      cache - the cache used to store and retrieve cacheable API responses
  • Method Details

    • generateResponse

      public HttpResponse generateResponse(HttpRequest httpReq) throws Exception
      Generates a response by proxying the request to the target API. Injects the required API key based on the target endpoint.
      Parameters:
      httpReq - the incoming HTTP request to proxy*
      Returns:
      the HTTP response from the external API, or an error response if the target is unknown or the key is missing
      Throws:
      Exception - if an error occurs during proxying