Package cx.syndeo.script
Interface HttpCallable
public interface HttpCallable
Interface for making HTTP calls.
Provides methods to configure and execute various HTTP request types (GET, POST, PUT, DELETE).
An instance of this interface is created via syndeo.prepareHttpCall(url).
Sample JavaScript Usage
// Prepare the HTTP call to a target URL
var request = syndeo.prepareHttpCall("https://api.example.com/data");
request.setQueryString({
key1: "value1",
key2: "value2"
})
request.addHeader("Content-Type", "application/json");
request.addHeader("Authorization", "Bearer <your-api-token>");
var requestBody = {
"clientId": "${clientId}", // A variable that might be interpolated by Syndeo
"user": "test-user"
};
request.setBody(requestBody);
var response = null;
var statusCode = 0;
try {
response = request.post();
statusCode = request.getLastStatusCode();
syndeo.log.info(`API call successful with status ${statusCode}.`);
} catch (e) {
if (e.getStatusCode) {
statusCode = e.getStatusCode();
}
syndeo.log.error(`API call failed. Expected 2xx response but received ${statusCode}.`);
}
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe maximum allowed read timeout in milliseconds (120000ms or 2 minutes).static final intThe minimum allowed read timeout in milliseconds (0). -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a header to the HTTP request.delete()Executes an HTTP DELETE request.get()Executes an HTTP GET request.intGets the HTTP status code from the last executed call.post()Executes an HTTP POST request.put()Executes an HTTP PUT request.voidSets the request body from a raw string.voidsetQueryString(Object queryParams) Sets the query string parameters for the URL from a Map.voidsetReadTimeout(long httpReadTimeoutMillis_p) Set the read timeout value for the HTTP call.
-
Field Details
-
MIN_HTTP_READ_TIMEOUT_MS
static final int MIN_HTTP_READ_TIMEOUT_MSThe minimum allowed read timeout in milliseconds (0).- See Also:
-
MAX_HTTP_READ_TIMEOUT_MS
static final int MAX_HTTP_READ_TIMEOUT_MSThe maximum allowed read timeout in milliseconds (120000ms or 2 minutes).- See Also:
-
-
Method Details
-
setReadTimeout
void setReadTimeout(long httpReadTimeoutMillis_p) throws cx.syndeo.scripting.exceptions.SyndeoScriptingException Set the read timeout value for the HTTP call. This method updates the read timeout value to the provided value if it is within the valid range.- Parameters:
httpReadTimeoutMillis_p- the new read timeout value in milliseconds- Throws:
IllegalArgumentException- if the provided read timeout value is less than 0 or greater than 120000.cx.syndeo.scripting.exceptions.SyndeoScriptingException
-
addHeader
Adds a header to the HTTP request.- Parameters:
name_p- The name of the header.value_p- The value of the header.
-
setBody
Sets the request body from a raw string.- Parameters:
body_p- The request body as a string.
-
getLastStatusCode
int getLastStatusCode()Gets the HTTP status code from the last executed call.- Returns:
- The integer value of the HTTP status code, or 0 if no call has been made.
-
setQueryString
void setQueryString(Object queryParams) throws cx.syndeo.scripting.exceptions.SyndeoScriptingException Sets the query string parameters for the URL from a Map.- Parameters:
queryParams- An object, expected to be a string key/value pair map.- Throws:
cx.syndeo.scripting.exceptions.SyndeoScriptingException- if the provided object is not a Map, contains invalid keys/values, or if the number of parameters exceeds the maximum allowed limit.
-
get
Executes an HTTP GET request.- Returns:
- The response body as a string.
- Throws:
cx.syndeo.scripting.RestException- if the HTTP call fails or returns a non-2xx status code.
-
post
Executes an HTTP POST request.- Returns:
- The response body as a string.
- Throws:
cx.syndeo.scripting.RestException- if the HTTP call fails or returns a non-2xx status code.
-
put
Executes an HTTP PUT request.- Returns:
- The response body as a string.
- Throws:
cx.syndeo.scripting.RestException- if the HTTP call fails or returns a non-2xx status code.
-
delete
Executes an HTTP DELETE request.- Returns:
- The response body as a string.
- Throws:
cx.syndeo.scripting.RestException- if the HTTP call fails or returns a non-2xx status code.
-