Package com.ebasetech.xi.services
Interface RestResponse
public interface RestResponse
RestResponse
contains the following response information following a RestServices
call:
- HTTP Code - HTTP Response code return from the
RestServices
call - Response Headers - All the HTTP response headers as key-->value String pairs
- Body - A String representation of the response body
RestServices
- Since:
- V5.1
-
Method Summary
Modifier and Type Method Description java.lang.String
getBody()
Returns the response body as a string representation following aRestServices
callint
getCode()
Returns the HTTP response code following aRestServices
calljava.util.Map<java.lang.String,java.lang.String>
getHeaders()
Returns the response headers as key-->value string pairs following aRestServices
call The key-->value pairs are returned as a JavaScript object.boolean
isSuccess()
Returns whether response code is successful following aRestServices
call.
-
Method Details
-
getCode
int getCode()Returns the HTTP response code following aRestServices
call- Since:
- V5.1
- See Also:
RestServices
-
getHeaders
java.util.Map<java.lang.String,java.lang.String> getHeaders()Returns the response headers as key-->value string pairs following aRestServices
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 }
- Since:
- V5.1
- See Also:
RestServices
-
getBody
java.lang.String getBody()Returns the response body as a string representation following aRestServices
callThe 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()); }
- Since:
- V5.1
- See Also:
RestServices
-
isSuccess
boolean isSuccess()Returns whether response code is successful following aRestServices
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 }
- Since:
- V5.1
- See Also:
RestServices
-