Path replacement does not happen inside the base URL of the API endpoint, only the relative URL string on the method. I'm going to assume you don't want to prefix the relative URLs on every one of your interface method declarations.
While poorly worded, the javadoc of Endpoint
states:
Callers should always consult the instance for the latest values rather than caching the returned values.
This means that for every request the Endpoint
instance will be consulted for the value of the base URL.
You can supply a custom Endpoint
implementation on which you can change the API key value:
public final class FooEndpoint implements Endpoint {
private static final String BASE = "http://192.168.1.64:5050/api/";
private String url;
public void setApiKey(String apiKey) {
url = BASE + apiKey;
}
@Override public String getName() {
return "default";
}
@Override public String getUrl() {
if (url == null) throw new IllegalStateException("API key not set.");
return url;
}
}