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.
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 keep retry and retry_on_connrefused at their defaults — curl retries connection-refused until the server accepts connections, so the task succeeds once the runner is up. List the runner in the polling task's start_on, and read the runner address as ${{tasks.<runner-id>.ip-address}}.


For the workflow syntax these examples use, see the workflow definition reference in the Swale documentation.

Licensed under the MIT License.