<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: Calling REST Webservice (HTTP GET)</title><link>https://answers.axonivy.com/questions/527/calling-rest-webservice-http-get</link><description>&lt;pre&gt;&lt;code&gt;I'm trying to use a currency converter in Xpert.ivy: http://rate-exchange.appspot.com. This service is called like this: http://rate-exchange.appspot.com/currency?from=EUR&amp;amp;to=CHF and gives a response like this: {"to": "CHF", "rate": 1.2223900000000001, "from": "EUR"}.

I would like this to call in a script step. So far I tried the method described in http://www.javacodegeeks.com/2012/09/simple-rest-client-in-java.html:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

  HttpClient client = new DefaultHttpClient();
  HttpGet request = new HttpGet("http://rate-exchange.appspot.com/currency?from=EUR&amp;amp;to=CHF");
  HttpResponse response = client.execute(request);
  BufferedReader rd = new BufferedReader (new InputStreamReader(response.getEntity().getContent()));
  String line = "";
  while ((line = rd.readLine()) != null) {
    out.SOME_STRING_DATATYPE = line;
  }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;At execution this throws an error in line 'HttpResponse response = client.execute(request);'&lt;/p&gt;
&lt;p&gt;Is there a better method to use a REST webservice from within Xpert.ivy?&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/527/calling-rest-webservice-http-get" rel="self"></atom:link><language>en</language><lastBuildDate>Thu, 20 Feb 2014 09:11:16 -0500</lastBuildDate><item><title>Answer by Reto Weiss</title><link>https://answers.axonivy.com/questions/527/calling-rest-webservice-http-get/539</link><description>&lt;p&gt;&lt;strong&gt;REST is supported by Axon.ivy since 6.1 out of the box.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The Axon.ivy Designer comes with a sample project called 'ConnectivityDemos' where the REST capabilities are demonstrated.&lt;/p&gt;
&lt;p&gt;See also the documentation about how to provide or call a REST service from Axon.ivy:
&lt;a href="http://developer.axonivy.com/doc/latest/DesignerGuideHtml/ivy.integration.html#ivy-integration-rest"&gt;http://developer.axonivy.com/doc/latest/DesignerGuideHtml/ivy.integration.html#ivy-integration-rest&lt;/a&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;strong&gt;For Axon.ivy 6.0 and older&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Unfortunately REST Web Services are not supported by default yet. &lt;/p&gt;
&lt;p&gt;But you can use a JAX-RS client library like &lt;a href="https://jersey.java.net/"&gt;Jersey&lt;/a&gt; to call REST Web Services. To do this, simple add the needed jersey libraries (.jar files) to your project. Then add the jar files to the Java Classpath (Switch to Java perspective. Select the jar file and use the context menu &lt;em&gt;Build Path &amp;gt; Add to Build Path&lt;/em&gt;). &lt;/p&gt;
&lt;p&gt;After that you can access the classes provided by the library from your own java classes but also from ivyScript. See Jersey user documentation chapter &lt;a href="https://jersey.java.net/documentation/latest/client.html"&gt;Client API&lt;/a&gt;  to learn how to use it.&lt;/p&gt;
&lt;p&gt;Sample project which makes a google search via Rest API: &lt;a href="http://www.ivyteam.ch/demo/RestFulWebService.iar"&gt;RestFulWebService.iar&lt;/a&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Reto Weiss</dc:creator><pubDate>Thu, 20 Feb 2014 09:11:16 -0500</pubDate><guid>https://answers.axonivy.com/questions/527/calling-rest-webservice-http-get/539</guid></item></channel></rss>