How to make rest API calls from within a plugin

Hi,

I’m developing a custom sonar plugin.
In this, I’m creating a sonar webservice, which collects data from sonar Rest APIs, performs some other actions and returns a consolidated results.

Now we have multiple sonar instances where I want to install this plugin.
Like: dev-myinstance-sonar.com or prod-myinstance-sonar.com

While calling sonar’s internal REST call (say api/measures/component), I cannot tell if the base URL will be dev or prod.
So how should I make call only providing the API path, without providing base URL?

Sample code:
import org.sonarqube.ws.WsMeasures;

public class MyPlgin implements WebService {


	@Override
    public void define(Context context) {
		
		// Call REST api
		String urlStr = "/api/measures/component";  <--- This doesn't work. Sonar throws Malformed url exception.
		
		URL url = new URL(urlStr);
		BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
		
		......
	
	}
}

Please suggest.
Thanks

The way that I have made api calls inside of sonarqube is by using a Sensor. Sensor’s have a wide range of functionality and making external calls is something that you can do in them. I would check the example git for an example.