HTTP request

swaleio/[email protected]

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

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 in the Swale documentation.

Licensed under the MIT License.