From 25fd2806395b6f6e92015fc6ea02cc14d9bd0aaf Mon Sep 17 00:00:00 2001 From: Shane <6071159+smashedr@users.noreply.github.com> Date: Thu, 6 Nov 2025 21:02:14 -0800 Subject: [PATCH 1/9] Add filename Input --- .github/workflows/test.yaml | 5 +++++ README.md | 33 +++++++++++++++------------------ action.yml | 2 ++ dist/index.js | 24 ++++++++++++++++++++---- src/index.js | 24 ++++++++++++++++++++---- 5 files changed, 62 insertions(+), 26 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 0996fe6..08564ba 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -37,13 +37,18 @@ jobs: uses: ./ with: url: https://httpbin.org/post + #url: http://192.168.1.25:8080/post + #insecure: true #data: '{"key": "value"}' data: | key: value params: | param1: value1 + file: event.json + filename: not-event.json - name: "Verify Outputs" + if: ${{ !github.event.act }} run: | echo 'status: ${{ steps.test.outputs.status }}' echo 'headers: ${{ steps.test.outputs.headers }}' diff --git a/README.md b/README.md index 576455d..5aece22 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ Pass data/headers/params as JSON or YAML formatted strings. insecure: false file: path/to/file.txt name: file + filename: better-file-name.txt ``` > [!NOTE] @@ -58,18 +59,19 @@ Pass data/headers/params as JSON or YAML formatted strings. ## Inputs -| Input | Default | Description of the Input Value | -| :------- | :--------- | :------------------------------------------------- | -| url | _Required_ | URL for Request [⤵️](#url) | -| method | `POST` | Request Method [⤵️](#method) | -| data | - | Request Data JSON/YAML [⤵️](#data) | -| 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 | +| Input | Default Value | Description of the Input Value | +| :------- | :----------------- | :------------------------------------------------- | +| url | _Required_ | URL for Request [⤵️](#url) | +| method | `POST` | Request Method [⤵️](#method) | +| data | - | Request Data JSON/YAML [⤵️](#data) | +| 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 | +| filename | _Original Name_ | Set a File Name | ### url @@ -120,12 +122,7 @@ key `name`. The file path is relative to the workspace/working directory. For more information on inputs, see: https://axios-http.com/docs/req_config -```yaml -- name: 'Web Request' - uses: cssnr/web-request-action@v1 - with: - url: https://httpbin.org/post -``` +See the [Examples](#examples) for more usage options... ## Outputs diff --git a/action.yml b/action.yml index 2b8229d..7d76983 100644 --- a/action.yml +++ b/action.yml @@ -30,6 +30,8 @@ inputs: name: description: "File Key Name" default: "file" + filename: + description: "Custom File Name" outputs: status: diff --git a/dist/index.js b/dist/index.js index 261a81b..5454b3d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -41541,6 +41541,11 @@ const https = __nccwpck_require__(5692) const yaml = __nccwpck_require__(4281) async function main() { + const version = process.env.GITHUB_ACTION_REF + ? `\u001b[35;1m${process.env.GITHUB_ACTION_REF}` + : 'Source' + core.info(`🏳️ Starting Web Request Action - ${version}`) + // Inputs core.startGroup('Inputs') const url = core.getInput('url', { required: true }) @@ -41563,25 +41568,32 @@ async function main() { console.log('file:', file) const name = core.getInput('name') console.log('name:', name) + const filename = core.getInput('filename') + console.log('filename:', filename) core.endGroup() // Inputs // Options - const auth = username && password ? { username, password } : {} - console.log('auth:', auth) + core.startGroup('Options') const httpsAgent = insecure ? new https.Agent({ rejectUnauthorized: false, }) : null console.log('httpsAgent:', httpsAgent) + const auth = username && password ? { username, password } : {} + console.log('auth:', auth) + const options = filename ? { filename } : {} + console.log('options:', options) + core.endGroup() // Options // File if (file) { + core.info('🔁 Converting Data to FormData') const form = new src_FormData() for (const [key, value] of Object.entries(data)) { form.append(key, value) } - form.append(name, fs.createReadStream(file)) + form.append(name, fs.createReadStream(file), options) Object.assign(headers, form.getHeaders()) data = form } @@ -41597,10 +41609,13 @@ async function main() { httpsAgent, } console.log('config:', config) + core.info('⌛ Processing Request') const response = await axios.request(config) console.log('response.status:', response.status) + // console.log('response:', response) // console.log('response.request._headers:', response.request._headers) + core.startGroup('Headers') console.log('response.headers:', response.headers) core.endGroup() // Headers @@ -41610,11 +41625,12 @@ async function main() { core.endGroup() // Data // Outputs + core.info('📩 Setting Outputs') core.setOutput('status', response.status) core.setOutput('headers', response.headers) core.setOutput('data', response.data) - core.info(`\u001b[32;1mFinished Success`) + core.info(`✅ \u001b[32;1mFinished Success`) } /** diff --git a/src/index.js b/src/index.js index a35a436..be800e0 100644 --- a/src/index.js +++ b/src/index.js @@ -6,6 +6,11 @@ const https = require('https') const yaml = require('js-yaml') async function main() { + const version = process.env.GITHUB_ACTION_REF + ? `\u001b[35;1m${process.env.GITHUB_ACTION_REF}` + : 'Source' + core.info(`🏳️ Starting Web Request Action - ${version}`) + // Inputs core.startGroup('Inputs') const url = core.getInput('url', { required: true }) @@ -28,25 +33,32 @@ async function main() { console.log('file:', file) const name = core.getInput('name') console.log('name:', name) + const filename = core.getInput('filename') + console.log('filename:', filename) core.endGroup() // Inputs // Options - const auth = username && password ? { username, password } : {} - console.log('auth:', auth) + core.startGroup('Options') const httpsAgent = insecure ? new https.Agent({ rejectUnauthorized: false, }) : null console.log('httpsAgent:', httpsAgent) + const auth = username && password ? { username, password } : {} + console.log('auth:', auth) + const options = filename ? { filename } : {} + console.log('options:', options) + core.endGroup() // Options // File if (file) { + core.info('🔁 Converting Data to FormData') const form = new FormData() for (const [key, value] of Object.entries(data)) { form.append(key, value) } - form.append(name, fs.createReadStream(file)) + form.append(name, fs.createReadStream(file), options) Object.assign(headers, form.getHeaders()) data = form } @@ -62,10 +74,13 @@ async function main() { httpsAgent, } console.log('config:', config) + core.info('⌛ Processing Request') const response = await axios.request(config) console.log('response.status:', response.status) + // console.log('response:', response) // console.log('response.request._headers:', response.request._headers) + core.startGroup('Headers') console.log('response.headers:', response.headers) core.endGroup() // Headers @@ -75,11 +90,12 @@ async function main() { core.endGroup() // Data // Outputs + core.info('📩 Setting Outputs') core.setOutput('status', response.status) core.setOutput('headers', response.headers) core.setOutput('data', response.data) - core.info(`\u001b[32;1mFinished Success`) + core.info(`✅ \u001b[32;1mFinished Success`) } /** From 79480f7368e3f8bb1206f221ef64e93093beb276 Mon Sep 17 00:00:00 2001 From: Shane <6071159+smashedr@users.noreply.github.com> Date: Thu, 6 Nov 2025 21:20:38 -0800 Subject: [PATCH 2/9] Update Test --- .github/workflows/test.yaml | 42 ++++++++++++++++++++++++++++++------- dist/index.js | 7 +++++-- src/index.js | 7 +++++-- 3 files changed, 44 insertions(+), 12 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 08564ba..1584924 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -32,8 +32,33 @@ jobs: GITHUB_CTX: ${{ toJSON(github) }} run: echo "$GITHUB_CTX" - - name: "Test Local Action" - id: test + - name: "1: Test Data" + id: test1 + uses: ./ + with: + url: https://httpbin.org/post + #url: http://192.168.1.25:8080/post + #insecure: true + #data: '{"key": "value"}' + data: | + key: value + params: | + param1: value1 + + - name: "1: Verify Data" + #if: ${{ !github.event.act }} + run: | + echo 'status: ${{ steps.test1.outputs.status }}' + echo 'headers: ${{ steps.test1.outputs.headers }}' + echo 'data: ${{ steps.test1.outputs.data }}' + if [ '${{ fromJson(steps.test1.outputs.data).data }}' != '{"key":"value"}' ];then + echo "Output Invalid" + exit 1 + fi + + - name: "2: Test File" + #if: ${{ !github.event.act }} + id: test2 uses: ./ with: url: https://httpbin.org/post @@ -47,13 +72,14 @@ jobs: file: event.json filename: not-event.json - - name: "Verify Outputs" - if: ${{ !github.event.act }} + - name: "2: Verify File" + #if: ${{ !github.event.act }} run: | - 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 'status: ${{ steps.test2.outputs.status }}' + echo 'headers: ${{ steps.test2.outputs.headers }}' + echo 'data: ${{ steps.test2.outputs.data }}' + echo 'data.form: ${{ fromJson(steps.test2.outputs.data).form.key }}' + if [ '${{ fromJson(steps.test2.outputs.data).form.key }}' != 'value' ];then echo "Output Invalid" exit 1 fi diff --git a/dist/index.js b/dist/index.js index 5454b3d..d52b158 100644 --- a/dist/index.js +++ b/dist/index.js @@ -41598,7 +41598,7 @@ async function main() { data = form } - // Request + // Config const config = { url, method, @@ -41608,11 +41608,14 @@ async function main() { auth, httpsAgent, } + core.startGroup('Config') console.log('config:', config) + core.endGroup() // Config + + // Request core.info('⌛ Processing Request') const response = await axios.request(config) console.log('response.status:', response.status) - // console.log('response:', response) // console.log('response.request._headers:', response.request._headers) diff --git a/src/index.js b/src/index.js index be800e0..b2b154f 100644 --- a/src/index.js +++ b/src/index.js @@ -63,7 +63,7 @@ async function main() { data = form } - // Request + // Config const config = { url, method, @@ -73,11 +73,14 @@ async function main() { auth, httpsAgent, } + core.startGroup('Config') console.log('config:', config) + core.endGroup() // Config + + // Request core.info('⌛ Processing Request') const response = await axios.request(config) console.log('response.status:', response.status) - // console.log('response:', response) // console.log('response.request._headers:', response.request._headers) From cdfaa56d013f49af3309bd905d7a470013c8c121 Mon Sep 17 00:00:00 2001 From: Shane <6071159+smashedr@users.noreply.github.com> Date: Thu, 6 Nov 2025 22:08:34 -0800 Subject: [PATCH 3/9] Use URL constructor --- .github/workflows/test.yaml | 9 +++++---- dist/index.js | 38 +++++++++++++++++++++++++++++++------ src/index.js | 14 ++++++++------ 3 files changed, 45 insertions(+), 16 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 1584924..57b3ee6 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -15,6 +15,9 @@ on: - "action.yml" pull_request: +env: + httpbin: ${{ !github.event.act && 'https://httpbin.org' || 'http://192.168.1.25:8080' }} + jobs: test: name: "Test" @@ -36,8 +39,7 @@ jobs: id: test1 uses: ./ with: - url: https://httpbin.org/post - #url: http://192.168.1.25:8080/post + url: "${{ env.httpbin }}/post" #insecure: true #data: '{"key": "value"}' data: | @@ -61,8 +63,7 @@ jobs: id: test2 uses: ./ with: - url: https://httpbin.org/post - #url: http://192.168.1.25:8080/post + url: "${{ env.httpbin }}/post" #insecure: true #data: '{"key": "value"}' data: | diff --git a/dist/index.js b/dist/index.js index d52b158..56c82d8 100644 --- a/dist/index.js +++ b/dist/index.js @@ -34475,6 +34475,30 @@ module.exports = require("node:events"); /***/ }), +/***/ 3264: +/***/ ((module) => { + +"use strict"; +module.exports = require("node:form-data"); + +/***/ }), + +/***/ 3024: +/***/ ((module) => { + +"use strict"; +module.exports = require("node:fs"); + +/***/ }), + +/***/ 4708: +/***/ ((module) => { + +"use strict"; +module.exports = require("node:https"); + +/***/ }), + /***/ 7075: /***/ ((module) => { @@ -41533,18 +41557,20 @@ module.exports = /*#__PURE__*/JSON.parse('{"application/1d-interleaved-parityfec /******/ /************************************************************************/ var __webpack_exports__ = {}; +const fs = __nccwpck_require__(3024) +const https = __nccwpck_require__(4708) +const src_FormData = __nccwpck_require__(3264) + const core = __nccwpck_require__(7484) + const axios = __nccwpck_require__(7269) -const src_FormData = __nccwpck_require__(6454) -const fs = __nccwpck_require__(9896) -const https = __nccwpck_require__(5692) const yaml = __nccwpck_require__(4281) async function main() { const version = process.env.GITHUB_ACTION_REF - ? `\u001b[35;1m${process.env.GITHUB_ACTION_REF}` + ? `${process.env.GITHUB_ACTION_REF}` : 'Source' - core.info(`🏳️ Starting Web Request Action - ${version}`) + core.info(`🏳️ Starting Web Request Action - \u001b[35;1m${version}`) // Inputs core.startGroup('Inputs') @@ -41600,7 +41626,7 @@ async function main() { // Config const config = { - url, + url: new URL(url), method, headers, params, diff --git a/src/index.js b/src/index.js index b2b154f..162ccb0 100644 --- a/src/index.js +++ b/src/index.js @@ -1,15 +1,17 @@ +const fs = require('node:fs') +const https = require('node:https') +const FormData = require('node:form-data') + const core = require('@actions/core') + const axios = require('axios') -const FormData = require('form-data') -const fs = require('fs') -const https = require('https') const yaml = require('js-yaml') async function main() { const version = process.env.GITHUB_ACTION_REF - ? `\u001b[35;1m${process.env.GITHUB_ACTION_REF}` + ? `${process.env.GITHUB_ACTION_REF}` : 'Source' - core.info(`🏳️ Starting Web Request Action - ${version}`) + core.info(`🏳️ Starting Web Request Action - \u001b[35;1m${version}`) // Inputs core.startGroup('Inputs') @@ -65,7 +67,7 @@ async function main() { // Config const config = { - url, + url: new URL(url), method, headers, params, From 4ab3e1c4815bf08bb4b358bd46ad31d9da9a13b5 Mon Sep 17 00:00:00 2001 From: Shane <6071159+smashedr@users.noreply.github.com> Date: Thu, 6 Nov 2025 22:10:56 -0800 Subject: [PATCH 4/9] Fix --- dist/index.js | 10 +--------- src/index.js | 2 +- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/dist/index.js b/dist/index.js index 56c82d8..68cca3a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -34475,14 +34475,6 @@ module.exports = require("node:events"); /***/ }), -/***/ 3264: -/***/ ((module) => { - -"use strict"; -module.exports = require("node:form-data"); - -/***/ }), - /***/ 3024: /***/ ((module) => { @@ -41559,11 +41551,11 @@ module.exports = /*#__PURE__*/JSON.parse('{"application/1d-interleaved-parityfec var __webpack_exports__ = {}; const fs = __nccwpck_require__(3024) const https = __nccwpck_require__(4708) -const src_FormData = __nccwpck_require__(3264) const core = __nccwpck_require__(7484) const axios = __nccwpck_require__(7269) +const src_FormData = __nccwpck_require__(6454) const yaml = __nccwpck_require__(4281) async function main() { diff --git a/src/index.js b/src/index.js index 162ccb0..b6d6128 100644 --- a/src/index.js +++ b/src/index.js @@ -1,10 +1,10 @@ const fs = require('node:fs') const https = require('node:https') -const FormData = require('node:form-data') const core = require('@actions/core') const axios = require('axios') +const FormData = require('form-data') const yaml = require('js-yaml') async function main() { From 27f6b0473563bed76a26676da5c932112ce92af7 Mon Sep 17 00:00:00 2001 From: Shane <6071159+smashedr@users.noreply.github.com> Date: Thu, 6 Nov 2025 22:20:27 -0800 Subject: [PATCH 5/9] url.parse is internal --- dist/index.js | 2 +- src/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 68cca3a..330b5b9 100644 --- a/dist/index.js +++ b/dist/index.js @@ -41618,7 +41618,7 @@ async function main() { // Config const config = { - url: new URL(url), + url, method, headers, params, diff --git a/src/index.js b/src/index.js index b6d6128..143cfe7 100644 --- a/src/index.js +++ b/src/index.js @@ -67,7 +67,7 @@ async function main() { // Config const config = { - url: new URL(url), + url, method, headers, params, From 17fb717fd4b2cc3ad8d14a6e7302a587176752b9 Mon Sep 17 00:00:00 2001 From: Shane <6071159+smashedr@users.noreply.github.com> Date: Thu, 6 Nov 2025 23:06:48 -0800 Subject: [PATCH 6/9] Update README.md --- README.md | 4 ++-- action.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5aece22..945b942 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ Pass data/headers/params as JSON or YAML formatted strings. insecure: false file: path/to/file.txt name: file - filename: better-file-name.txt + filename: custom-name.txt ``` > [!NOTE] @@ -71,7 +71,7 @@ Pass data/headers/params as JSON or YAML formatted strings. | insecure | `false` | Ignore SSL Errors | | file | - | File Path to Send [⤵️](#file) | | name | `file` | File Form Key Name | -| filename | _Original Name_ | Set a File Name | +| filename | _Original Name_ | Set a Different File Name | ### url diff --git a/action.yml b/action.yml index 7d76983..6d3a371 100644 --- a/action.yml +++ b/action.yml @@ -1,5 +1,5 @@ name: "Web Request" -description: "Send Web Requests like POST and GET with Axios using GitHub Actions." +description: "Easily Make Web Requests like GET/POST, Trigger Webhooks, and Send Files using Axios. Data inputs supports YAML/JSON format." author: "Shane" branding: icon: "globe" From 1f21824cfb5076da3db538d0c20420d6c82f5889 Mon Sep 17 00:00:00 2001 From: Shane <6071159+smashedr@users.noreply.github.com> Date: Thu, 6 Nov 2025 23:37:06 -0800 Subject: [PATCH 7/9] Allow Empty Username/Password --- .github/workflows/test.yaml | 6 +++--- action.yml | 6 +++--- dist/index.js | 2 +- src/index.js | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 57b3ee6..782d000 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -48,7 +48,7 @@ jobs: param1: value1 - name: "1: Verify Data" - #if: ${{ !github.event.act }} + if: ${{ !github.event.act }} run: | echo 'status: ${{ steps.test1.outputs.status }}' echo 'headers: ${{ steps.test1.outputs.headers }}' @@ -59,7 +59,7 @@ jobs: fi - name: "2: Test File" - #if: ${{ !github.event.act }} + if: ${{ !github.event.act }} id: test2 uses: ./ with: @@ -74,7 +74,7 @@ jobs: filename: not-event.json - name: "2: Verify File" - #if: ${{ !github.event.act }} + if: ${{ !github.event.act }} run: | echo 'status: ${{ steps.test2.outputs.status }}' echo 'headers: ${{ steps.test2.outputs.headers }}' diff --git a/action.yml b/action.yml index 6d3a371..dcee21a 100644 --- a/action.yml +++ b/action.yml @@ -13,11 +13,11 @@ inputs: description: "Request Method" default: "POST" data: - description: "Request Data JSON" + description: "Request Data JSON/YAML" headers: - description: "Request Headers JSON" + description: "Request Headers JSON/YAML" params: - description: "Request Parameters JSON" + description: "Request Parameters JSON/YAML" username: description: "Basic Auth Username" password: diff --git a/dist/index.js b/dist/index.js index 330b5b9..72b1979 100644 --- a/dist/index.js +++ b/dist/index.js @@ -41598,7 +41598,7 @@ async function main() { }) : null console.log('httpsAgent:', httpsAgent) - const auth = username && password ? { username, password } : {} + const auth = username || password ? { username, password } : {} console.log('auth:', auth) const options = filename ? { filename } : {} console.log('options:', options) diff --git a/src/index.js b/src/index.js index 143cfe7..a2260a1 100644 --- a/src/index.js +++ b/src/index.js @@ -47,7 +47,7 @@ async function main() { }) : null console.log('httpsAgent:', httpsAgent) - const auth = username && password ? { username, password } : {} + const auth = username || password ? { username, password } : {} console.log('auth:', auth) const options = filename ? { filename } : {} console.log('options:', options) From 438d41e0ef4a81bbf45f976dd9617f285fa0fb5b Mon Sep 17 00:00:00 2001 From: Shane <6071159+smashedr@users.noreply.github.com> Date: Fri, 7 Nov 2025 00:26:59 -0800 Subject: [PATCH 8/9] Add Config Input --- .github/workflows/test.yaml | 2 ++ README.md | 25 ++++++++++++++++++++++++- action.yml | 4 ++++ dist/index.js | 15 ++++++--------- src/index.js | 15 ++++++--------- 5 files changed, 42 insertions(+), 19 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 782d000..a4d30cc 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -46,6 +46,8 @@ jobs: key: value params: | param1: value1 + config: | + timeout: 30000 - name: "1: Verify Data" if: ${{ !github.event.act }} diff --git a/README.md b/README.md index 945b942..296b4e6 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,7 @@ Pass data/headers/params as JSON or YAML formatted strings. | data | - | Request Data JSON/YAML [⤵️](#data) | | headers | - | Request Headers JSON/YAML [⤵️](#headers) | | params | - | Request Parameters JSON/YAML [⤵️](#params) | +| config | - | Axios Config JSON/YAML [⤵️](#config) | | username | - | Basic Auth Username | | password | - | Basic Auth Password | | insecure | `false` | Ignore SSL Errors | @@ -79,7 +80,7 @@ The URL to send the request too. You may include params here or in the [params]( ### method -The request method, including custom methods. +The request method, including custom methods. Case-insensitive. Default: `POST` @@ -115,6 +116,12 @@ Headers JSON or YAML data. Parameters, Query String, JSON or YAML data. These may also be provided in the [url](#url). +### config + +Additional Axios Config JSON or YAML data. For example, set a 3-second timeout: `timeout: 3000` + +Reference: https://axios-http.com/docs/req_config + ### file When sending a file, `multipart/form-data` wil be used and `data` will be added to the form data with the @@ -205,8 +212,24 @@ See the [Examples](#examples) for more usage options... url: https://httpbin.org/post file: path/to/file.txt name: file # Default - name of file key + filename: name.txt # Optional - file name ``` + +
Set Axios Config + +```yaml +- name: 'Web Request' + uses: cssnr/web-request-action@v1 + with: + url: https://httpbin.org/post + config: | + timeout: 1000 + maxContentLength: 2000 +``` + +Reference: https://axios-http.com/docs/req_config +
All Inputs diff --git a/action.yml b/action.yml index dcee21a..7e6a8ac 100644 --- a/action.yml +++ b/action.yml @@ -18,6 +18,8 @@ inputs: description: "Request Headers JSON/YAML" params: description: "Request Parameters JSON/YAML" + config: + description: "Axios Config JSON/YAML" username: description: "Basic Auth Username" password: @@ -40,6 +42,8 @@ outputs: description: "Response Headers" data: description: "Response Data" + #url: + # description: "Response URL" runs: using: "node24" diff --git a/dist/index.js b/dist/index.js index 72b1979..1552ec2 100644 --- a/dist/index.js +++ b/dist/index.js @@ -41576,6 +41576,8 @@ async function main() { console.log('headers:', headers) const params = parseData('params') console.log('params:', params) + let config = parseData('config') + console.log('config:', config) const username = core.getInput('username') console.log('username:', username) const password = core.getInput('password') @@ -41611,21 +41613,14 @@ async function main() { for (const [key, value] of Object.entries(data)) { form.append(key, value) } + core.debug(`Adding file: ${file}`) form.append(name, fs.createReadStream(file), options) Object.assign(headers, form.getHeaders()) data = form } // Config - const config = { - url, - method, - headers, - params, - data, - auth, - httpsAgent, - } + config = { url, method, headers, params, data, auth, httpsAgent, ...config } core.startGroup('Config') console.log('config:', config) core.endGroup() // Config @@ -41635,6 +41630,7 @@ async function main() { const response = await axios.request(config) console.log('response.status:', response.status) // console.log('response:', response) + // console.log('responseUrl:', response.request?.res?.responseUrl) // console.log('response.request._headers:', response.request._headers) core.startGroup('Headers') @@ -41650,6 +41646,7 @@ async function main() { core.setOutput('status', response.status) core.setOutput('headers', response.headers) core.setOutput('data', response.data) + // core.setOutput('url', response.request?.res?.responseUrl || '') core.info(`✅ \u001b[32;1mFinished Success`) } diff --git a/src/index.js b/src/index.js index a2260a1..5564350 100644 --- a/src/index.js +++ b/src/index.js @@ -25,6 +25,8 @@ async function main() { console.log('headers:', headers) const params = parseData('params') console.log('params:', params) + let config = parseData('config') + console.log('config:', config) const username = core.getInput('username') console.log('username:', username) const password = core.getInput('password') @@ -60,21 +62,14 @@ async function main() { for (const [key, value] of Object.entries(data)) { form.append(key, value) } + core.debug(`Adding file: ${file}`) form.append(name, fs.createReadStream(file), options) Object.assign(headers, form.getHeaders()) data = form } // Config - const config = { - url, - method, - headers, - params, - data, - auth, - httpsAgent, - } + config = { url, method, headers, params, data, auth, httpsAgent, ...config } core.startGroup('Config') console.log('config:', config) core.endGroup() // Config @@ -84,6 +79,7 @@ async function main() { const response = await axios.request(config) console.log('response.status:', response.status) // console.log('response:', response) + // console.log('responseUrl:', response.request?.res?.responseUrl) // console.log('response.request._headers:', response.request._headers) core.startGroup('Headers') @@ -99,6 +95,7 @@ async function main() { core.setOutput('status', response.status) core.setOutput('headers', response.headers) core.setOutput('data', response.data) + // core.setOutput('url', response.request?.res?.responseUrl || '') core.info(`✅ \u001b[32;1mFinished Success`) } From 7a32b9c605e05b7cc397e3e33df79e5d08dad89a Mon Sep 17 00:00:00 2001 From: Shane <6071159+smashedr@users.noreply.github.com> Date: Fri, 7 Nov 2025 00:51:17 -0800 Subject: [PATCH 9/9] Update README.md --- README.md | 53 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 296b4e6..10d51a8 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,8 @@ Pass data/headers/params as JSON or YAML formatted strings. { "key": "value" } + config: | + timeout: 1000 username: ${{ secrets.USERNAME }} password: ${{ secrets.PASSWORD }} insecure: false @@ -86,12 +88,14 @@ Default: `POST` ### data -Body JSON or YAML data. Only used for `PUT`, `POST`, `DELETE`, and `PATCH`. +Body JSON/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).
View JSON/YAML Example +This format works for `data`, `headers`, `params`, and `config`. + ```yaml data: | key1: value1 @@ -106,22 +110,36 @@ data: | } ``` +```yaml +data: '{"key1": "value1", "key2": "value2"}' +``` + +Note: All these examples are identical. +
### headers -Headers JSON or YAML data. +Headers JSON/YAML data. ### params -Parameters, Query String, JSON or YAML data. These may also be provided in the [url](#url). +Parameters (Query String) JSON/YAML data. These may also be provided in the [url](#url). ### config -Additional Axios Config JSON or YAML data. For example, set a 3-second timeout: `timeout: 3000` +Additional Axios Config JSON/YAML data. For example, set a 3-second timeout: `timeout: 3000` Reference: https://axios-http.com/docs/req_config +
Note: The config is spread last and overrides other keys. + +```javascript +config = { url, method, headers, params, data, auth, httpsAgent, ...config } +``` + +
+ ### file When sending a file, `multipart/form-data` wil be used and `data` will be added to the form data with the @@ -139,6 +157,8 @@ See the [Examples](#examples) for more usage options... | headers | Response Headers | | data | Response Data | +Note: All outputs are run through `JSON.stringify` by default. + ```yaml - name: 'Web Request' id: test @@ -157,10 +177,20 @@ See the [Examples](#examples) for more usage options... 💡 _Click on an example heading to expand or collapse the example._ -
Algolia Start Crawl +
Trigger a Webhook ```yaml -- name: 'Algolia Start Crawl' +- name: 'Portainer Webhook' + uses: cssnr/web-request-action@v1 + with: + url: ${{ secrets.PORTAINER_WEBHOOK }} +``` + +
+
Start Algolia Crawl + +```yaml +- name: 'Start Algolia Crawl' uses: cssnr/web-request-action@v1 with: url: https://crawler.algolia.com/api/1/crawlers/${{ secrets.CRAWLER_ID }}/reindex @@ -172,7 +202,7 @@ See the [Examples](#examples) for more usage options...
Deploy to Render ```yaml -- name: 'Render Deploy' +- name: 'Render Deploy Image' uses: cssnr/web-request-action@v1 with: url: ${{ secrets.RENDER_HOOK }} @@ -200,8 +230,14 @@ See the [Examples](#examples) for more usage options... with: url: https://httpbin.org/post data: '{"key": "value"}' + data: | + '{"key": "value"}' + data: | + key: value ``` +Note: All data keys are identical as exemplar formats. +
Send File @@ -246,11 +282,14 @@ Reference: https://axios-http.com/docs/req_config { "key": "value" } + config: | + timeout: 5000 username: ${{ secrets.USERNAME }} password: ${{ secrets.PASSWORD }} insecure: false file: path/to/file.txt name: file + filename: name.txt ```