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

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The maximum allowed read timeout in milliseconds (120000ms or 2 minutes).
    static final int
    The minimum allowed read timeout in milliseconds (0).
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addHeader(String name_p, String value_p)
    Adds a header to the HTTP request.
    Executes an HTTP DELETE request.
    get()
    Executes an HTTP GET request.
    int
    Gets the HTTP status code from the last executed call.
    Executes an HTTP POST request.
    put()
    Executes an HTTP PUT request.
    void
    setBody(String body_p)
    Sets the request body from a raw string.
    void
    setQueryString(Object queryParams)
    Sets the query string parameters for the URL from a Map.
    void
    setReadTimeout(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_MS
      The minimum allowed read timeout in milliseconds (0).
      See Also:
    • MAX_HTTP_READ_TIMEOUT_MS

      static final int MAX_HTTP_READ_TIMEOUT_MS
      The 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

      void addHeader(String name_p, String value_p)
      Adds a header to the HTTP request.
      Parameters:
      name_p - The name of the header.
      value_p - The value of the header.
    • setBody

      void setBody(String body_p)
      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

      String get() throws cx.syndeo.scripting.RestException
      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

      String post() throws cx.syndeo.scripting.RestException
      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

      String put() throws cx.syndeo.scripting.RestException
      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

      String delete() throws cx.syndeo.scripting.RestException
      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.