# HTTP request

> **About this page**
>
> - Task definition version: `swaleio/http-request@8.14.1-r1`
> - Summary: Makes an HTTP request with curl, writing the response body to a file and emitting the status.
> - Published: 2026-11-30, the latest version
> - Page: https://hub.swale.io/swaleio/http-request/v/8.14.1-r1
> - Latest version's copy: https://hub.swale.io/swaleio/http-request.md
> - Versions: https://hub.swale.io/swaleio/http-request/versions
> - Index of Swale Hub: https://hub.swale.io/llms.txt
>
> The YAML block below is the task definition's frontmatter, which declares its inputs, outputs and container, and its readme follows. Both are the text of the account that published this task definition, not Swale's.

```yaml
name: HTTP request
description: Makes an HTTP request with curl, writing the response body to a file and emitting the status.
category: utilities
inputs:
  url:
    description: The request URL. The public internet is reachable; RFC 1918 and cloud metadata endpoints are blocked.
    required: true
  method:
    description: HTTP method (GET, POST, PUT, PATCH, DELETE, HEAD, ...).
    default: GET
  headers:
    description: 'Request headers as newline-separated "Key: Value" lines. The wrapper splits on newlines and passes each as a header; blank lines are ignored.'
    default: ""
  body:
    description: Request body sent verbatim. Ignored when body_file is set.
    default: ""
  body_file:
    description: Workspace path whose file contents are sent as the request body. Takes precedence over body.
    default: ""
  retry:
    description: Number of times curl retries transient failures (transient HTTP 5xx and connection errors), with backoff.
    default: "3"
  retry_on_connrefused:
    description: When true, also retry on connection-refused — use it to poll a runner that is reachable but not yet accepting connections.
    default: "true"
  retry_delay:
    description: Seconds to wait between retries. Empty waits 1 second before the first retry and doubles the wait after each one; set it to check a starting server at a steady pace.
    default: ""
  expected_status:
    description: If set, the task fails unless the final response status code equals this value. Empty means accept any status.
    default: ""
  response_path:
    description: Path where the response body is written. A bare relative path lands in the container's working directory; pass an absolute workspace path (e.g. ${{env.WORKFLOW_STORAGE}}/response.json) to share the body with downstream tasks. Use a distinct path per task since the workspace is shared.
    default: response.json
outputs:
  status:
    description: The HTTP status code of the final response.
  body_file:
    description: Path of the written response body (equals response_path).
exec:
  # docker.io/swaleio/curl-jq:8.14.1-r1
  image: docker.io/swaleio/curl-jq@sha256:5c502ca48317c348f7a0ab434960e6419f863a51de2a2a73ffb2ec9251fd1496
  args: []
```

# HTTP request

Makes an HTTP request and captures the result for downstream tasks: the response
body is written to a workspace file and the status code is emitted as an output.
The image's entrypoint is the request wrapper, so there are no `args` — **every
setting is supplied through inputs** (each is also injected as an `INPUT_*`
environment variable the wrapper reads).

Use it to call APIs, submit jobs, download small JSON/text payloads into the
workspace, and to poll a not-yet-ready runner until it starts answering.

## Inputs

| Input | Required | Default | Description |
|-------|----------|---------|-------------|
| `url` | yes | — | The request URL (public internet only; private ranges are blocked). |
| `method` | no | `GET` | HTTP method. |
| `headers` | no | — | Newline-separated `Key: Value` header lines; the wrapper splits them. |
| `body` | no | — | Request body sent verbatim. Ignored when `body_file` is set. |
| `body_file` | no | — | Workspace path whose contents are sent as the body; wins over `body`. |
| `retry` | no | `3` | Retries for transient 5xx and connection errors, with backoff. |
| `retry_on_connrefused` | no | `true` | Also retry connection-refused — for polling a runner that isn't up yet. |
| `retry_delay` | no | — | Seconds between retries. Empty waits 1 second, then doubles the wait after each retry. |
| `expected_status` | no | any | If set, the task fails unless the response code matches this value. |
| `response_path` | no | `response.json` | Where the response body is written; a relative path lands in the working directory — pass an absolute workspace path to share it downstream. |

## Outputs

| Output | Description |
|--------|-------------|
| `status` | The HTTP status code of the final response. |
| `body_file` | Path of the written response body (equals `response_path`). |

## Compute

**CPU.** HTTP I/O only — no GPU is needed, and scheduling it on a GPU compute type wastes money.

## Example

```yaml
name: HTTP request example
compute_type: cpu-4
entry_point: main

blocks:
  main:
    tasks:
      submit:
        name: Submit job
        uses: swaleio/http-request
        args:
          url: https://api.example.com/v1/jobs
          method: POST
          headers: |
            Authorization: Bearer ${{secrets.api_token}}
            Content-Type: application/json
          body: '{"name":"nightly","priority":"high"}'
          expected_status: "201"
          response_path: ${{env.WORKFLOW_STORAGE}}/job.json
```

The response body is available to later tasks at
`${{tasks.submit.outputs.body_file}}` (here `${{env.WORKFLOW_STORAGE}}/job.json`), and the
status code as `${{tasks.submit.outputs.status}}`.

## Polling a runner

To wait for a long-running runner task to become ready, point `url` at its
health endpoint and set `retry: "360"` and `retry_delay: "5"`: the task checks
every 5 seconds for up to 30 minutes and succeeds once the server answers.
`retry_on_connrefused` keeps its default, so a server that is still starting
and refusing connections is retried too. Raise `retry` for a server that takes
longer to start, such as one that first downloads a large model.

The defaults are not enough for this. With `retry: "3"` and no delay, curl
gives up about 7 seconds after the first refused connection, and without a
delay the wait doubles after every retry, so a check can come minutes after the
server is up.

List the runner in the polling task's `start_on`, and read the runner address
as `${{tasks.<runner-id>.ip-address}}`. The `vllm-serve` and `ollama-serve`
examples poll their servers this way.

---

For the workflow syntax these examples use, see the
[workflow definition reference](https://docs.swale.io/reference/workflow-definition-syntax)
in the [Swale documentation](https://docs.swale.io).

Licensed under the [MIT License](https://github.com/swaleio/task-definitions/blob/main/LICENSE).
