RestServices.get

Performs a REST HTTP GET call supplying any request headers and/or parameters. Returns a RestResponse representing the response. A GET is a read only call.

RestResponse contains the following data:

  • HTTP response code - returns a HTTP response code e.g 200 (OK)
  • HTTP response headers - returns list of response headers as key-->value pairs. e.g "WWW-Authenticate", "Bearer"
  • Response body - returns the response body if the response is successful. If there is no response, this value will be null.

Example:

 var uri = "http://example.com/rest/users";
 //set any headers
 var headers = {"Content-Type":"application/json", "Accept":"application/json"};
 //set params
 var params = {"userId":fields.filter.value};
 //create authentication 
 var auth = HttpAuthentication.createBasicAuthentication("username", "password");
 var opts = new RestOptions();
 //setting the wait time to establish a connection to the target server to 5 seconds
 opts.setConnectionTimeout(5);
 //set the time to wait for no inactivity from the rest call to 10 seconds
 opts.setSocketTimeout(10);
 //set UTF-8 character set when decoding the response
 opts.setResponseCharset("UTF-8");
 var body = "{'request':'all'}";
 var response = services.rest.get(uri, headers, params, auth, opts, body);
 if(response.isSuccess())
 {
      var results = JSON.parse(response.getBody());
      if(results)
      {
           //populate results using the JSON object
           populateResults(results);
      }
 }
 
Further documentation.

returns RestResponse

Parameters

java.lang.String  uri,  java.util.Map  headers,  java.util.Map  parameters,  Authentication authentication,  RestOptions options,  java.lang.String  body,