diff --git a/CHANGELOG.md b/CHANGELOG.md index c10d64560..22336b7e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ Since v0.0.10, this Changelog is formatted according to the [Common Changelog][c ## UNRELEASED +### Added +- ([#318](https://github.com/demos-europe/demosplan-ui/pull/318)) Add a method called externalApi to make external API calls without including default headers ([@sakutademos](https://github.com/sakutademos)) + ## v0.1.6 - 2023-06-22 ### Changed @@ -227,4 +230,4 @@ Same as v0.0.13, but with up-to-date build dependencies this time around. --- -[common-changelog]: https://common-changelog.org \ No newline at end of file +[common-changelog]: https://common-changelog.org diff --git a/src/index.js b/src/index.js index 40f858247..a96f85448 100644 --- a/src/index.js +++ b/src/index.js @@ -105,6 +105,7 @@ import { Detabinator, dpApi, dpRpc, + externalApi, getCssVariable, getFileInfo, getFileTypes, @@ -171,6 +172,7 @@ export default { length, dpApi, dpRpc, + externalApi, dpValidate, dpValidateMultiselectDirective, DpButton, diff --git a/src/lib/DpApi.js b/src/lib/DpApi.js index 0083098dc..bbe58130d 100644 --- a/src/lib/DpApi.js +++ b/src/lib/DpApi.js @@ -88,6 +88,21 @@ const dpRpc = function (method, parameters, id = null) { }) } +/** + * Perform an external API call without any default headers + */ +const externalApi = function (url) { + const contentType = axios.defaults.headers.common['Content-Type'] + delete axios.defaults.headers.common['Content-Type'] + + return axios.get(url).then(response => { + // Restore the Content-Type header + axios.defaults.headers.common['Content-Type'] = contentType + + return response + }) +} + /** * Turn messages into notifications * @@ -172,4 +187,4 @@ function makeFormPost (payload, url) { }) } -export { dpApi, handleResponseMessages, checkResponse, dpRpc, makeFormPost } +export { dpApi, handleResponseMessages, checkResponse, dpRpc, makeFormPost, externalApi } diff --git a/src/lib/index.js b/src/lib/index.js index fc0001c60..cbaa49750 100644 --- a/src/lib/index.js +++ b/src/lib/index.js @@ -1,4 +1,4 @@ -import { checkResponse, dpApi, dpRpc, handleResponseMessages, makeFormPost } from './DpApi' +import { checkResponse, dpApi, dpRpc, externalApi, handleResponseMessages, makeFormPost } from './DpApi' import { convertSize, getFileInfo, getFileTypes, mimeTypes } from './FileInfo' import { highlightActiveLinks } from './HighlightHashLink' import ActionMenu from './ActionMenu' @@ -19,6 +19,7 @@ export { Detabinator, dpApi, dpRpc, + externalApi, getCssVariable, getFileInfo, getFileTypes,