# HTTP Client

> Make HTTP Requests.

Source: https://docs.sommatic.ai/en/nodes/io.http/

- Slug: `io.http`
- Family: Input and output
- Version: 1.0.0
- Status: Available
- Execution: async

Make HTTP Requests.

## Configuration

- `connection_id` (string, optional): Optional credential for the HTTP request. Accepts credentials of type `api-key`, `basic-auth`, `oauth2`, or `object` (custom headers / auth).
- `url` (string, required, accepts expressions): Full URL or Path if connection used.
- `method` (string, optional): Default: `GET`. Allowed values: `GET`, `POST`, `PUT`, `PATCH`, `DELETE`.
- `headers` (object, optional, accepts expressions): HTTP headers as key-value pairs.
- `body` (object, optional, accepts expressions): JSON body. Supports {{expressions}}.

Supports the shared execution settings: retries (`retryOnFail`, `maxTries`, `waitBetweenTries`) and timeout.

## Output ports

- `out` (default): Successful HTTP response (2xx)
- `error`: HTTP client_error (4xx) or server_error (5xx)

## Input contract

- `connection_id` (string, optional)
- `url` (string, required)
- `method` (string, optional)
- `headers` (object, optional)
- `body` (object, optional)

## Output contract

- `status` (number, optional)
- `headers` (object, optional)
- `data` (object, optional): Response Body

## In expressions

What a later node can read from this node's output with `$("HTTP Client").item.json.<path>` (write your node's label instead of `HTTP Client`). **Editor** marks the paths the workflow editor suggests under Previous Nodes (the output contract); **Worker** marks the paths the worker really returns through `out`, from the output shown in Ports.

- `$("HTTP Client").item.json.status` (number) = `200`
- `$("HTTP Client").item.json.headers` (object) = `{…}`
- `$("HTTP Client").item.json.data` (object) = `{…}`: Response Body
- `$("HTTP Client").item.json.data.id` (string) = `"ord_123"` (Not suggested by the editor)
- `$("HTTP Client").item.json.data.status` (string) = `"paid"` (Not suggested by the editor)
- `$("HTTP Client").item.json.headers.content-type` (string) = `"application/json; charset=utf-8"` (Not suggested by the editor)


## How it works

Sends one HTTP request, optionally authenticated with a credential resolved on the server, and retries rate-limit, 5xx and transient network failures with exponential backoff.

1. Resolves the config: expressions in `url`, `headers` and `body` are evaluated against the run.
2. With `connection_id`, resolves the credential: prefixes `config.baseUrl` when `url` does not start with `http`, and adds one auth header from the secret, first match wins: `token` → `Authorization: Bearer`, `username` + `password` → `Authorization: Basic`, `apiKey` → header `config.headerName` (default `x-api-key`).
3. Computes the retry policy (see `http_retry_*` and `execution`).
4. Sends `method` to `url` with `headers` and `body` as the request data, over IPv4. Every status is accepted by the client and classified by the worker.
5. 2xx leaves through `out` with `{ status, data, headers }`. 429 and 5xx are retried while attempts remain, as are transient network errors; anything else leaves through `error` at once.

## In a workflow

### Node

```json
{
  "node_id": "node-call-erp",
  "label": "Call ERP",
  "operator_slug": "io.http",
  "operator_version": "1.0.0",
  "config": {
    "url": "https://api.example.com/orders/{{ $json.order_id }}",
    "method": "GET",
    "headers": {
      "accept": "application/json"
    },
    "connection_id": "pi-credential-xxxx",
    "http_retry_max_attempts": 3,
    "http_retry_backoff_ms": 1000
  }
}
```

### Envelope

```json
{
  "ok": true,
  "data": {
    "status": 200,
    "data": {
      "id": "ord_123",
      "status": "paid"
    },
    "headers": {
      "content-type": "application/json; charset=utf-8"
    }
  },
  "port": "out"
}
```

## Output ports (behaviour in the code)

### `out`

The server answered with a 2xx status. `data` is the parsed response body (JSON when the server sends JSON, otherwise text).

```json
{
  "status": 200,
  "data": {
    "id": "ord_123",
    "status": "paid"
  },
  "headers": {
    "content-type": "application/json; charset=utf-8"
  }
}
```

### `error`

A non-2xx status after the last attempt (data is `{ status, data, message }`), or a network or setup failure (data is `{ error, response }`).

```json
{
  "status": 404,
  "data": {
    "message": "Order not found"
  },
  "message": "HTTP Request Failed with status 404"
}
```

## Behaviour in the code

- `http_retry_max_attempts`: Not declared in the schema. Total number of attempts, including the first. Wins over `execution`. Values below 1 or not numeric become 1; capped at 5.
- `http_retry_backoff_ms`: Not declared. Base wait in ms (falls back to `execution.waitBetweenTries`, then 1000). Wait before retry n is `base × 2^(n−1)` plus 0–249 ms of jitter, capped by `http_retry_max_wait_ms`.
- `http_retry_max_wait_ms`: Not declared. Upper bound of a single wait, default 20000, never above 30000.
- `execution`: Used only when `http_retry_max_attempts` is absent: `retryOnFail: false` gives 1 attempt; otherwise `maxTries` attempts (default 3). Without an `execution` block the node makes up to 3 attempts. `timeout_ms`, `continueOnFail` and `alwaysOutputData` are not applied by this worker.
- `method`: When empty, the request is sent as GET.
- `connection_id`: The secret must be an object with `token`, `username` + `password` or `apiKey`, as in `basic-auth`, `oauth2` or `object` credentials. An `api-key` credential stored as a plain string adds no header. `config.baseUrl` and `config.headerName` come from the credential config.

## Errors

| Message | Port | Cause and fix |
| --- | --- | --- |
| `HTTP Request Failed with status <status>` | `error` | The server answered non-2xx. 4xx other than 429 are never retried; 429 and 5xx reach this port only after the last attempt. `data` holds the response body. |
| `<network error message>` | `error` | The connection failed (for example `connect ETIMEDOUT`, `getaddrinfo ENOTFOUND`) on every attempt, or failed with a non-transient error. Check the URL and that the host is reachable from the orchestrator. |
| `Failed to resolve connection <connection_id>: <detail>` | `error` | The credential does not exist or this workflow cannot use it. Not retried. |

## Notes and limits

- Retried statuses: 429 and 500–599. Retried network errors: `ETIMEDOUT`, `ECONNRESET`, `ECONNREFUSED`, `ECONNABORTED`, `ENOTFOUND`, `EAI_AGAIN`, `EPIPE`, `ENETUNREACH`, `EHOSTUNREACH`, and any error whose message contains "timeout".
- Retries resend the same request: make non-idempotent calls (POST, PATCH) safe to repeat, or set `http_retry_max_attempts: 1`.
- The request itself has no timeout; a server that never answers keeps the node waiting.
- Connections are forced to IPv4 and are not kept alive between runs.


## Contracts (JSON Schema)

### All (`*.definition.js`)

```json
{
  "slug": "io.http",
  "name": "HTTP Client",
  "category": "io",
  "version": "1.0.0",
  "description": "Make HTTP Requests.",
  "capabilities": [
    "http",
    "api",
    "rest"
  ],
  "config_schema": {
    "type": "object",
    "properties": {
      "connection_id": {
        "type": "string",
        "title": "HTTP Credential (optional)",
        "description": "Optional credential for the HTTP request. Accepts credentials of type `api-key`, `basic-auth`, `oauth2`, or `object` (custom headers / auth).",
        "ui_widget": "connection_picker",
        "ui_options": {
          "credential_types": [
            "api-key",
            "basic-auth",
            "oauth2",
            "object"
          ],
          "types": [
            "http"
          ]
        }
      },
      "url": {
        "type": "string",
        "title": "URL",
        "description": "Full URL or Path if connection used.",
        "format": "expression"
      },
      "method": {
        "type": "string",
        "title": "Method",
        "enum": [
          "GET",
          "POST",
          "PUT",
          "PATCH",
          "DELETE"
        ],
        "default": "GET"
      },
      "headers": {
        "type": "object",
        "title": "Headers",
        "description": "HTTP headers as key-value pairs.",
        "format": "expression"
      },
      "body": {
        "type": "object",
        "title": "Body",
        "description": "JSON body. Supports {{expressions}}.",
        "format": "expression"
      },
      "execution": {
        "type": "object",
        "title": "Execution Settings",
        "properties": {
          "alwaysOutputData": {
            "type": "boolean",
            "title": "Always Output Data",
            "description": "Always output data, even on error (if configured).",
            "default": false
          },
          "retryOnFail": {
            "type": "boolean",
            "title": "Retry On Fail",
            "description": "Retry the execution if it fails.",
            "default": false
          },
          "maxTries": {
            "type": "integer",
            "title": "Max Retries",
            "description": "Number of retries.",
            "default": 3,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "waitBetweenTries": {
            "type": "integer",
            "title": "Wait Between Retries (ms)",
            "default": 1000,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "continueOnFail": {
            "type": "boolean",
            "title": "Continue On Fail",
            "description": "Do not crash workflow on error.",
            "default": false
          },
          "timeout_ms": {
            "type": "integer",
            "title": "Timeout (ms)",
            "description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
            "default": 300000
          }
        }
      }
    },
    "required": [
      "url"
    ]
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "connection_id": {
        "type": "string"
      },
      "url": {
        "type": "string"
      },
      "method": {
        "type": "string"
      },
      "headers": {
        "type": "object"
      },
      "body": {
        "type": "object"
      }
    },
    "required": [
      "url"
    ]
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "status": {
        "type": "number"
      },
      "headers": {
        "type": "object"
      },
      "data": {
        "type": "object",
        "description": "Response Body"
      }
    }
  },
  "ports": [
    {
      "port_id": "out",
      "label": "Response",
      "description": "Successful HTTP response (2xx)",
      "is_default": true,
      "supports_condition": true
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "HTTP client_error (4xx) or server_error (5xx)",
      "is_default": false,
      "supports_condition": true
    }
  ],
  "execution_mode": "async",
  "required_resources": [],
  "compatible_worker_pools": [
    "standard-io",
    "high-throughput-io"
  ],
  "tags": [
    "api",
    "rest"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_link_loom",
    "profile": {
      "name": "Link Loom",
      "verified": true,
      "url": "https://me.veripass.com/link-loom",
      "logo_url": null
    }
  }
}
```

### config_schema

```json
{
  "type": "object",
  "properties": {
    "connection_id": {
      "type": "string",
      "title": "HTTP Credential (optional)",
      "description": "Optional credential for the HTTP request. Accepts credentials of type `api-key`, `basic-auth`, `oauth2`, or `object` (custom headers / auth).",
      "ui_widget": "connection_picker",
      "ui_options": {
        "credential_types": [
          "api-key",
          "basic-auth",
          "oauth2",
          "object"
        ],
        "types": [
          "http"
        ]
      }
    },
    "url": {
      "type": "string",
      "title": "URL",
      "description": "Full URL or Path if connection used.",
      "format": "expression"
    },
    "method": {
      "type": "string",
      "title": "Method",
      "enum": [
        "GET",
        "POST",
        "PUT",
        "PATCH",
        "DELETE"
      ],
      "default": "GET"
    },
    "headers": {
      "type": "object",
      "title": "Headers",
      "description": "HTTP headers as key-value pairs.",
      "format": "expression"
    },
    "body": {
      "type": "object",
      "title": "Body",
      "description": "JSON body. Supports {{expressions}}.",
      "format": "expression"
    },
    "execution": {
      "type": "object",
      "title": "Execution Settings",
      "properties": {
        "alwaysOutputData": {
          "type": "boolean",
          "title": "Always Output Data",
          "description": "Always output data, even on error (if configured).",
          "default": false
        },
        "retryOnFail": {
          "type": "boolean",
          "title": "Retry On Fail",
          "description": "Retry the execution if it fails.",
          "default": false
        },
        "maxTries": {
          "type": "integer",
          "title": "Max Retries",
          "description": "Number of retries.",
          "default": 3,
          "displayOptions": {
            "show": {
              "retryOnFail": [
                true
              ]
            }
          }
        },
        "waitBetweenTries": {
          "type": "integer",
          "title": "Wait Between Retries (ms)",
          "default": 1000,
          "displayOptions": {
            "show": {
              "retryOnFail": [
                true
              ]
            }
          }
        },
        "continueOnFail": {
          "type": "boolean",
          "title": "Continue On Fail",
          "description": "Do not crash workflow on error.",
          "default": false
        },
        "timeout_ms": {
          "type": "integer",
          "title": "Timeout (ms)",
          "description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
          "default": 300000
        }
      }
    }
  },
  "required": [
    "url"
  ]
}
```

### input_contract_schema

```json
{
  "type": "object",
  "properties": {
    "connection_id": {
      "type": "string"
    },
    "url": {
      "type": "string"
    },
    "method": {
      "type": "string"
    },
    "headers": {
      "type": "object"
    },
    "body": {
      "type": "object"
    }
  },
  "required": [
    "url"
  ]
}
```

### output_contract_schema

```json
{
  "type": "object",
  "properties": {
    "status": {
      "type": "number"
    },
    "headers": {
      "type": "object"
    },
    "data": {
      "type": "object",
      "description": "Response Body"
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "out",
    "label": "Response",
    "description": "Successful HTTP response (2xx)",
    "is_default": true,
    "supports_condition": true
  },
  {
    "port_id": "error",
    "label": "Error",
    "description": "HTTP client_error (4xx) or server_error (5xx)",
    "is_default": false,
    "supports_condition": true
  }
]
```
