Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat(T33336): add externalApi method for external requests #318

Merged
merged 7 commits into from
Jun 23, 2023
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: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
[common-changelog]: https://common-changelog.org
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ import {
Detabinator,
dpApi,
dpRpc,
externalApi,
getCssVariable,
getFileInfo,
getFileTypes,
Expand Down Expand Up @@ -171,6 +172,7 @@ export default {
length,
dpApi,
dpRpc,
externalApi,
dpValidate,
dpValidateMultiselectDirective,
DpButton,
Expand Down
17 changes: 16 additions & 1 deletion src/lib/DpApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -172,4 +187,4 @@ function makeFormPost (payload, url) {
})
}

export { dpApi, handleResponseMessages, checkResponse, dpRpc, makeFormPost }
export { dpApi, handleResponseMessages, checkResponse, dpRpc, makeFormPost, externalApi }
3 changes: 2 additions & 1 deletion src/lib/index.js
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -19,6 +19,7 @@ export {
Detabinator,
dpApi,
dpRpc,
externalApi,
getCssVariable,
getFileInfo,
getFileTypes,
Expand Down