@vespaiach/axios-fetch-adapter
Advanced tools
Comparing version 0.3.0 to 0.3.1
import { AxiosRequestConfig, AxiosPromise } from 'axios'; | ||
export default function fetchAdapter(config: AxiosRequestConfig): AxiosPromise; |
@@ -5,3 +5,3 @@ import axios from 'axios'; | ||
import buildFullPath from 'axios/lib/core/buildFullPath'; | ||
import { isUndefined } from 'axios/lib/utils'; | ||
import { isUndefined, isStandardBrowserEnv, isFormData } from 'axios/lib/utils'; | ||
@@ -107,2 +107,8 @@ /** | ||
options.body = config.data; | ||
// In these cases the browser will automatically set the correct Content-Type, | ||
// but only if that header hasn't been set yet. So that's why we're deleting it. | ||
if (isFormData(options.body) && isStandardBrowserEnv()) { | ||
headers.delete('Content-Type'); | ||
} | ||
} | ||
@@ -109,0 +115,0 @@ if (config.mode) { |
{ | ||
"name": "@vespaiach/axios-fetch-adapter", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "Fetch adapter for axios", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -9,3 +9,3 @@ # Why | ||
``` | ||
``` sh | ||
npm install axios | ||
@@ -19,3 +19,3 @@ npm install @vespaiach/axios-fetch-adapter | ||
``` | ||
``` js | ||
const instance = axios.create({ | ||
@@ -31,3 +31,3 @@ baseURL: 'https://some-domain.com/api/', | ||
``` | ||
``` js | ||
axios.request({ | ||
@@ -41,4 +41,16 @@ url: '/user', | ||
3. Use with FormData | ||
``` js | ||
axios.request({ | ||
url: '/user', | ||
method: 'post', | ||
adapter: fetchAdapter | ||
data: new FormData(formId) | ||
... | ||
}) | ||
``` | ||
# Note | ||
- Since, this adapter relies on fetch API so it won't work in Node environment | ||
- Since, this adapter relies on fetch API so it won't work in Node environment |
@@ -17,1 +17,13 @@ import axios from 'axios'; | ||
}; | ||
formElem.onsubmit = async (e) => { | ||
e.preventDefault(); | ||
let response = await axios.request({ | ||
url: 'https://httpbin.org/post', | ||
method: 'post', | ||
data: new FormData(formElem), | ||
adapter: fetchAdapter, | ||
}); | ||
console.log(response); | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11321
220
53