Skip to content

Commit 17e98db

Browse files
committed
Allow to call the API with custom HTTP method
Change the request function to allow to specify the method, if not GET the parameters are sent in the body. Signed-off-by: thc202 <[email protected]>
1 parent 20cdef4 commit 17e98db

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
55

66
## [Unreleased]
7+
### Changed
8+
* Allow to call the ZAP API with custom HTTP method (e.g. file upload).
79

810
## [2.0.0-rc.3] - 2023-10-14
911
### Changed

src/index.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,23 @@ class ApiClientError extends Error {
120120
}
121121
}
122122

123-
ClientApi.prototype.request = async (url, data, format) => {
123+
ClientApi.prototype.request = async (url, data, format, method = 'GET') => {
124124
try {
125125
let requestConfig = structuredClone(defaultAxiosConfig)
126+
requestConfig.method = method
127+
requestConfig.url = url
126128
if (data) {
127-
requestConfig.params = { ...requestConfig.params, ...data }
129+
if (method === 'GET') {
130+
requestConfig.params = data
131+
} else {
132+
requestConfig.headers = { ...requestConfig.headers, ...{ 'content-type': 'application/x-www-form-urlencoded' } }
133+
requestConfig.data = data
134+
}
128135
}
129136
if (format === 'other') {
130137
requestConfig = { ...requestConfig, baseURL: BASE_URL_OTHER }
131138
}
132-
const response = await axios.get(url, requestConfig)
139+
const response = await axios.request(requestConfig)
133140

134141
return response.data
135142
} catch (error) {

0 commit comments

Comments
 (0)