Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ jobs:

- name: "Verify Outputs"
run: |
echo '${{ steps.test.outputs.status }}'
echo '${{ steps.test.outputs.data }}'
echo 'status: ${{ steps.test.outputs.status }}'
echo 'headers: ${{ steps.test.outputs.headers }}'
echo 'data: ${{ steps.test.outputs.data }}'
if [ '${{ fromJson(steps.test.outputs.data).data }}' != '{"key":"value"}' ];then
echo "Output Invalid"
exit 1
Expand Down
83 changes: 64 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,27 @@

Easily make a web request from a workflow using Axios.
Supports all methods, uploading files, basic authentication and more.
Pass data/headers/params as JSON or YAML formatted strings.

```yaml
- name: 'Web Request'
uses: cssnr/web-request-action@v1
with:
url: https://httpbin.org/post
method: 'POST'
data: '{"key": "value"}'
headers: |
key: value
params: |
{
"key": "value"
}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
insecure: false
file: path/to/file.txt
name: file
```

> [!NOTE]
> Please submit a [Feature Request](https://github.com/cssnr/web-request-action/discussions/categories/feature-requests)
Expand All @@ -38,42 +59,58 @@ Supports all methods, uploading files, basic authentication and more.

| Input | Default | Description of the Input Value |
| :------- | :--------- | :------------------------------------------------- |
| url | _Required_ | URL for Request |
| method | `POST` | Request Method |
| url | _Required_ | URL for Request [⤵️](#url) |
| method | `POST` | Request Method [⤵️](#method) |
| data | - | Request Data JSON/YAML [⤵️](#data) |
| headers | - | Request Headers JSON/YAML |
| headers | - | Request Headers JSON/YAML [⤵️](#headers) |
| params | - | Request Parameters JSON/YAML [⤵️](#params) |
| username | - | Basic Auth Username |
| password | - | Basic Auth Password |
| insecure | `false` | Ignore SSL Errors |
| file | - | File Path to Send [⤵️](#file) |
| name | `file` | File Form Key Name |

### url

The URL to send the request too. You may include params here or in the [params](#params) key.

### method

The request method, including custom methods.

Default: `POST`

### data

Only used for `PUT`, `POST`, `DELETE`, and `PATCH`. Data is parsed with `JSON.parse` then `yaml.load`.
Body JSON or YAML data. Only used for `PUT`, `POST`, `DELETE`, and `PATCH`.

Data is parsed with `JSON.parse` or `yaml.load`, [js-yaml](https://github.com/nodeca/js-yaml).

<details><summary>View Multi-Line JSON/YAML Example</summary>
<details><summary>View JSON/YAML Example</summary>

```yaml
data: |
{
"key1": "value1",
"key2": "value2"
}
key1: value1
key2: value2
```

```yaml
data: |
key1: value1
key2: value2
{
"key1": "value1",
"key2": "value2"
}
```

</details>

### headers

Headers JSON or YAML data.

### params

These can be specified in the URL or added here as JSON key/value pairs.
Parameters, Query String, JSON or YAML data. These may also be provided in the [url](#url).

### file

Expand All @@ -91,10 +128,11 @@ For more information on inputs, see: https://axios-http.com/docs/req_config

## Outputs

| Output | Description |
| :----- | :-------------- |
| status | Response Status |
| data | Response Data |
| Output | Description |
| :------ | :--------------- |
| status | Response Status |
| headers | Response Headers |
| data | Response Data |

```yaml
- name: 'Web Request'
Expand All @@ -106,6 +144,7 @@ For more information on inputs, see: https://axios-http.com/docs/req_config
- name: 'Echo Output'
run: |
echo '${{ steps.test.outputs.status }}'
echo '${{ steps.test.outputs.headers }}'
echo '${{ steps.test.outputs.data }}'
```

Expand All @@ -132,7 +171,8 @@ For more information on inputs, see: https://axios-http.com/docs/req_config
uses: cssnr/web-request-action@v1
with:
url: ${{ secrets.RENDER_HOOK }}
params: '{"imgURL": "ghcr.io/${{ github.repository }}:${{ github.ref_name }}"}'
params: |
imgURL: ghcr.io/${{ github.repository }}:${{ github.ref_name }}
```

</details>
Expand Down Expand Up @@ -166,6 +206,7 @@ For more information on inputs, see: https://axios-http.com/docs/req_config
with:
url: https://httpbin.org/post
file: path/to/file.txt
name: file # Default - name of file key
```

</details>
Expand All @@ -178,8 +219,12 @@ For more information on inputs, see: https://axios-http.com/docs/req_config
url: https://httpbin.org/post
method: 'POST'
data: '{"key": "value"}'
headers: '{"header": "value"}'
params: '{"parameter": "value"}'
headers: |
key: value
params: |
{
"key": "value"
}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
insecure: false
Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ inputs:
outputs:
status:
description: "Response Status"
headers:
description: "Response Headers"
data:
description: "Response Data"

Expand Down
18 changes: 13 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36240,7 +36240,7 @@ module.exports = parseParams
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {

"use strict";
/*! Axios v1.13.0 Copyright (c) 2025 Matt Zabriskie and contributors */
/*! Axios v1.13.1 Copyright (c) 2025 Matt Zabriskie and contributors */


const FormData$1 = __nccwpck_require__(6454);
Expand Down Expand Up @@ -38400,7 +38400,7 @@ function buildFullPath(baseURL, requestedURL, allowAbsoluteUrls) {
return requestedURL;
}

const VERSION = "1.13.0";
const VERSION = "1.13.1";

function parseProtocol(url) {
const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
Expand Down Expand Up @@ -39676,7 +39676,7 @@ const httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {

if (responseType === 'stream') {
response.data = responseStream;
settle(resolve, abort, response);
settle(resolve, reject, response);
} else {
const responseBuffer = [];
let totalResponseBytes = 0;
Expand Down Expand Up @@ -41538,6 +41538,7 @@ const yaml = __nccwpck_require__(4281)
;(async () => {
try {
// Inputs
core.startGroup('Inputs')
const url = core.getInput('url', { required: true })
console.log('url:', url)
const method = core.getInput('method', { required: true })
Expand All @@ -41558,6 +41559,7 @@ const yaml = __nccwpck_require__(4281)
console.log('file:', file)
const name = core.getInput('name')
console.log('name:', name)
core.endGroup() // Inputs

// Options
const auth = username && password ? { username, password } : {}
Expand Down Expand Up @@ -41592,14 +41594,20 @@ const yaml = __nccwpck_require__(4281)
}
console.log('config:', config)
const response = await axios.request(config)
console.log('response.status:', response.status)
// console.log('response:', response)
// console.log('response.request._headers:', response.request._headers)
// console.log('response.headers:', response.headers)
console.log('response.status:', response.status)
core.startGroup('Headers')
console.log('response.headers:', response.headers)
core.endGroup() // Headers

core.startGroup('Data')
console.log('response.data:', response.data)
core.endGroup() // Data

// Outputs
core.setOutput('status', response.status)
core.setOutput('headers', response.headers)
core.setOutput('data', response.data)

core.info(`\u001b[32;1mFinished Success`)
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"dependencies": {
"@actions/core": "^1.11.1",
"axios": "^1.13.0",
"axios": "^1.13.1",
"form-data": "^4.0.4",
"js-yaml": "^4.1.0"
},
Expand Down
12 changes: 10 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const yaml = require('js-yaml')
;(async () => {
try {
// Inputs
core.startGroup('Inputs')
const url = core.getInput('url', { required: true })
console.log('url:', url)
const method = core.getInput('method', { required: true })
Expand All @@ -28,6 +29,7 @@ const yaml = require('js-yaml')
console.log('file:', file)
const name = core.getInput('name')
console.log('name:', name)
core.endGroup() // Inputs

// Options
const auth = username && password ? { username, password } : {}
Expand Down Expand Up @@ -62,14 +64,20 @@ const yaml = require('js-yaml')
}
console.log('config:', config)
const response = await axios.request(config)
console.log('response.status:', response.status)
// console.log('response:', response)
// console.log('response.request._headers:', response.request._headers)
// console.log('response.headers:', response.headers)
console.log('response.status:', response.status)
core.startGroup('Headers')
console.log('response.headers:', response.headers)
core.endGroup() // Headers

core.startGroup('Data')
console.log('response.data:', response.data)
core.endGroup() // Data

// Outputs
core.setOutput('status', response.status)
core.setOutput('headers', response.headers)
core.setOutput('data', response.data)

core.info(`\u001b[32;1mFinished Success`)
Expand Down