A machine-readable index of this documentation for AI agents is available at https://kubevela.io/llms.txt. Markdown versions of documentation pages are available by appending .md to their URLs.
Skip to main content
Version: Workflow 0.6

Call an HTTP API and Use the Answer

This WorkflowRun asks the GitHub API about the kubevela/workflow repository, builds a sentence from the reply, and hands it to the next step. If the call fails, a different step runs instead. The same pattern sends the result on to Slack or a webhook: swap the last step for a notification step.

Needs: the vela-workflow controller (Install), and a cluster that can reach api.github.com.

The WorkflowRun​

github-stars.yaml
apiVersion: core.oam.dev/v1alpha1
kind: WorkflowRun
metadata:
name: github-stars
namespace: default
spec:
workflowSpec:
steps:
- name: request
type: request
properties:
url: https://api.github.com/repos/kubevela/workflow
outputs:
- name: stars
valueFrom: '"\(response.full_name) has \(response.stargazers_count) stars"'
- name: report
type: print-message-in-status
inputs:
- from: stars
parameterKey: message
- name: report-failure
type: print-message-in-status
if: status.request.failed
properties:
message: "Could not read the repository from GitHub"
  • request sends a GET and waits for the reply. It parses a JSON body into response, which valueFrom reads: here, CUE string interpolation over two of its fields.
  • report takes the output as its message, through inputs.
  • report-failure has an if, so it runs when the condition holds rather than only when everything before it succeeded.

Run it​

kubectl apply -f github-stars.yaml
kubectl get workflowrun github-stars
NAME PHASE AGE
github-stars succeeded 6s

Each step's phase and message:

kubectl get workflowrun github-stars \
-o jsonpath='{range .status.steps[*]}{.name}{"\t"}{.phase}{"\t"}{.message}{"\n"}{end}'
request succeeded
report succeeded kubevela/workflow has 127 stars
report-failure skipped

The star count is whatever GitHub says when you run it.

When the call fails​

Point the URL at a repository that doesn't exist, https://api.github.com/repos/kubevela/no-such-repo, and name the run github-stars-missing. GitHub answers 404, the request step fails, report is skipped since it needs request to succeed, and report-failure runs:

NAME PHASE AGE
github-stars-missing failed 6s
request failed request of https://api.github.com/repos/kubevela/no-such-repo is fail: 404
report skipped
report-failure succeeded Could not read the repository from GitHub

The run is failed because one of its steps failed, even though the fallback ran.

Clean up​

kubectl delete workflowrun github-stars github-stars-missing

Read more​