Advice on how to call a REST service from a Task

How can I call a REST based URL from a Task in order to run a report with parameters for example https://wiki.openmrs.org/display/docs/How+to+run+a+Reporting+Module+report+through+a+URL

Did you figure this out?

What is Task in this context?

@dkayiwa Nope I did not

Since you want to do this from a task, is there any reason why you do not just directly call the Java API instead of making a REST call?

@dkayiwa The Java API call requires dependency on the modules, so I thought making a call via the URL means that I do not have to reproduce the functionality

Don’t you need to have the module, anyway? :slight_smile:

That is why I was wondering maybe we are not talking about the same kind of tasks I know.

@dkayiwa If I already have a url which returns the report contents that I need, why go into Java code to replicate the same, just use existing functionality …

I aim to write as little code as possible that has to be tested, maintained and evolved

@ssmusoke

If what you want is to call the rest API to get the report from the java code you can spring RestTemplate.

Possibly, am not understanding you. If you want to make a REST call from a Java task, you will be writing more code than simply directly making a call to the Java API, which even your REST call is also eventually doing.

Yeah you are probably going to write more code. Anyway one way todo it would be to use HttpClient.