http:request
Perform HTTP requests using the provided configuration
Options
| Name | Type | Description |
|---|---|---|
url | string | The request URL; query parameters may be embedded or provided via Query |
method | string | The HTTP method: GET, POST, PATCH, PUT, DELETE |
query | map[string][]string | Additional query parameters merged with any already in the URL |
headers | map[string]string | Additional request headers |
token | string | Bearer token added to the Authorization header |
token_type | string | The authorization scheme prefix (defaults to "Bearer") |
body | any | The request body as a string or []byte |
Outputs
| Name | Type | Description |
|---|---|---|
code | int | The HTTP response status code |
body | string | The response body as a string |
Examples
Is the documented example workflow for the http component. It lives in a test file so docgen can read it for the docs without linking it into any binary. docgen keys it to the component by the config-struct name (HTTPConfig).
name: Fetch a page and save it
actions:
- name: page
component: http:request
vars:
method: GET
url: "https://example.com/api/status"
headers:
Accept: application/json
- name: save
component: storage:local:file:write
vars:
path: ./status.json
content: "{{ page.body }}"
outputs:
code: "{{ page.code }}"Post request
Posts a JSON body. A structured value under body is
sent as JSON, and the response body comes back as a string to parse downstream.
name: Create an issue
actions:
- name: created
component: http:request
vars:
method: POST
url: "{{ env.API }}/issues"
headers:
Content-Type: application/json
body:
title: "{{ var.title }}"
labels:
- automation
- name: issue
component: var
vars:
var: id
value: "{{ created.body | from:'json' | key:'id' }}"
outputs:
id: "{{ issue.id }}"Authentication
Sends a bearer token and query parameters. token
fills the Authorization header, token_type sets its scheme, and each query
key holds a list of values.
name: Search with an API token
actions:
- name: results
component: http:request
vars:
url: "{{ env.API }}/search"
token: "{{ env.API_TOKEN }}"
token_type: Bearer
query:
q:
- "{{ var.term }}"
limit:
- "10"
outputs:
body: "{{ results.body }}"