Skip to content

Commit

Permalink
Merge pull request #74 from thc202/custom-method
Browse files Browse the repository at this point in the history
Allow to call the API with custom HTTP method
  • Loading branch information
ricekot authored Nov 22, 2023
2 parents 20cdef4 + 17e98db commit b5d021d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

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

## [2.0.0-rc.3] - 2023-10-14
### Changed
Expand Down
13 changes: 10 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,23 @@ class ApiClientError extends Error {
}
}

ClientApi.prototype.request = async (url, data, format) => {
ClientApi.prototype.request = async (url, data, format, method = 'GET') => {
try {
let requestConfig = structuredClone(defaultAxiosConfig)
requestConfig.method = method
requestConfig.url = url
if (data) {
requestConfig.params = { ...requestConfig.params, ...data }
if (method === 'GET') {
requestConfig.params = data
} else {
requestConfig.headers = { ...requestConfig.headers, ...{ 'content-type': 'application/x-www-form-urlencoded' } }
requestConfig.data = data
}
}
if (format === 'other') {
requestConfig = { ...requestConfig, baseURL: BASE_URL_OTHER }
}
const response = await axios.get(url, requestConfig)
const response = await axios.request(requestConfig)

return response.data
} catch (error) {
Expand Down

0 comments on commit b5d021d

Please sign in to comment.