Skip to main content

HTTP Node

Overview

This node is used to execute HTTP tasks such as common POST and GET requests. Node success is determined based on the returned status code.

Node Configuration

Fill in the basic information for the current task node. Node Name and Description are optional, but they help you understand and manage the node more effectively and make the overall Offline Dev workflow clearer and easier to maintain.

  • Request URL: Supports GET and POST, with GET as the default. This field specifies the URL of the HTTP request.
  • Request parameter configuration:
Configuration ItemDescription
Request HeadersKey/value pairs that tell the server what type of resource is required.
AuthenticationCurrently supports two authentication methods: API Key and Token. API Key identifies the source of a request to a web service or similar service. Token represents a user role for a specified period and grants permission to call the interface.
Request ParametersThe fields and conditions to be retrieved. Supports Global Parameters, Time Macro Parameters, and Workflow Parameter.

Request BodyJSON only. Encapsulates the request parameters of a POST request and supports Global Parameters, Time Macro Parameters, and Workflow Parameter.

  • Validation rule: The node succeeds when the configured condition is met. If the response status code does not start with 2, such as 200 or 201, the task ends with an error.
  • Callback polling configuration: When the interface request takes a long time, you can configure callback polling to check the request status.
Configuration ItemDescription
Polling Interval (Seconds)Poll once every X seconds.
Callback URLSupports GET and POST, with GET as the default. This field specifies the callback URL.
Request HeadersKey/value pairs that tell the server what type of resource is required.
AuthenticationCurrently supports API Key and Token. API Key identifies the source of a request. Token represents a user role for a specified period and grants permission to call the interface.
Request ParametersThe fields and conditions to be retrieved. Supports Global Parameters, Time Macro Parameters, and Workflow Parameter.
Request BodyJSON only. Encapsulates the request parameters of a POST request and supports Global Parameters, Time Macro Parameters, and Workflow Parameter.

Callback Notes

  1. The main request must return parameters in the following format:
{
"taskId": "xxxxxx",
...
}
  1. The platform automatically extracts taskId and appends it to the callback URL.

    For example, the URL is automatically appended as http://127.0.0.1:8004/status/xxxxxx.

  2. Validate the callback result:

    1. The return format must be { "status": "xxxxxx", ... }.
    2. If the response status code does not start with 2, such as 200 or 201, the task ends with an error directly.
    3. If status is PROCESSING, polling continues. Otherwise, polling ends. SUCCESS means success; any other value means failure.
    4. Be careful to avoid infinite loops in the service.

Runtime Options

  • Run status
    • Do Not Execute: When the workflow reaches this node, execution is skipped directly. This is commonly used for temporary data troubleshooting and partial task execution control.
    • Normal: The node runs according to the existing scheduling strategy. This is the default run status.
  • Retry on failure
    • Retry count: The number of automatic retries after node failure. The default is 1.
    • Retry interval: The interval before each retry is triggered. The default is 5 minutes.
  • Timeout limit
    • Timeout duration: The timeout limit for a single node. The node fails automatically if the limit is exceeded.

|500

Example: Calling a Python Service Through HTTP

Dependencies required by the Python API service

flask
request
jsonify
cachetools

Python service script

# -*- coding: utf-8 -*-

from flask import Flask, request, jsonify
from concurrent.futures import ThreadPoolExecutor
from cachetools import TTLCache
import time
import uuid
import io
import contextlib
import sys


app = Flask(__name__)

# Thread pool (up to 10 concurrent tasks)
executor = ThreadPoolExecutor(max_workers=10)

# Convert 2 days to seconds
two_days_in_seconds = 2 * 24 * 60 * 60

# Create a cache object with a 2-day TTL for each entry
task_cache = TTLCache(maxsize=100, ttl=two_days_in_seconds)
def run_python_code(code, taskId):
"""Execute Python code and store the result."""
try:
result = execute_code(code)
task_cache[taskId] = {"taskId": taskId, "status": "FINISHED", "log": result}
except Exception as e:
task_cache[taskId] = {"taskId": taskId, "status": "FAILED", "error": str(e)}

@app.route("/run_code", methods=["POST"])
def run_code():
"""Submit a code task and run it asynchronously."""
data = request.get_json()
code = data.get("code", "").strip()

if not code:
return jsonify({"error": "No code provided"}), 400

# Generate a unique taskId
taskId = str(uuid.uuid4())

# Record task start
task_cache[taskId] = {"taskId": taskId, "status": "PROCESSING"}

# Submit the task to the thread pool
executor.submit(run_python_code, code, taskId)

return jsonify({"taskId": taskId, "status": "PROCESSING"})

@app.route("/status/<taskId>", methods=["GET"])
def check_status(taskId):
"""Query task status."""
if taskId not in task_cache:
return jsonify({"taskId": taskId, "status": "FAILED", "error": "Task not found"}), 404

task_info = task_cache[taskId]

if task_info["status"] == "FAILED":
return jsonify({"taskId": taskId, "status": "FAILED", "error": task_info["error"]}), 500
return jsonify(task_info)

# Function that executes the code
def execute_code(code):
# Use StringIO to capture print output
output_buffer = io.StringIO()
try:
# Redirect standard output to output_buffer
with contextlib.redirect_stdout(output_buffer):
exec(code)
# Get the captured output
output = output_buffer.getvalue()
return output.strip() # Return the captured output
except Exception as e:
# Return the error message if code execution fails
return f"Code execution failed: {str(e)}"
finally:
# Close the StringIO buffer
output_buffer.close()


if __name__ == "__main__":
app.run(host="0.0.0.0", port=8004, debug=True) # Listen on all addresses, port 8004

Configure the HTTP Node

Configure parameters in the request body

Configure the callback interface