public interface RestResponse
RestResponse contains the following response information following a RestServices call:
RestServices callRestServices| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
getBody()
Returns the response body as a string representation following a
RestServices call |
int |
getCode()
Returns the HTTP response code following a
RestServices call |
java.util.Map<java.lang.String,java.lang.String> |
getHeaders()
Returns the response headers as key-->value string pairs following a
RestServices call
The key-->value pairs are returned as a JavaScript object. |
boolean |
isSuccess()
Returns whether response code is successful following a
RestServices call. |
int getCode()
RestServices callRestServicesjava.util.Map<java.lang.String,java.lang.String> getHeaders()
RestServices call
The key-->value pairs are returned as a JavaScript object.
Accessing a key value where the name of the key has a hyphen in it needs to be accessed using headers["key-name"] syntax.
Example:
var response = services.rest.get("http://example.com/rest/users");
var headers = response.getHeaders();
var content = headers["Content-Type"];
if(content == 'application/json')
{
//do something with JSON
}
RestServicesjava.lang.String getBody()
RestServices call
The response body also contains the error message from a response if it is an unsuccessful call.
Example:
var response = services.rest.get("http://example.com/rest/users");
if(response.isSuccess())
{
var results = JSON.parse(response.getBody());
if(results)
{
//do something with the results
}
}
else
{
event.getOwner().addErrorMessage(response.getBody());
}
RestServicesboolean isSuccess()
RestServices call. A successful response code is in the HTTP 200 range.
Example:
var response = services.rest.get("http://example.com/rest/users");
if(response.isSuccess())
{
//do something
}
else
{
//show error
}
RestServices