- Fix: response interceptors should run only once with error-retry plugin
- Fix: response interceptors should run after plugins(Fix #29)
- Refactor:
content-type
detecting code improve and decrease size
- feat(core): Support
URLSearchParams
Fix issues/26
- fix(core): RangeError: Invalid time value. ref issues/23
- Fix(core): if params include
Date
value, call.toISOString()
and utilsencodeParams
support optionsallowDot: true
andarrayFormat: 'indices' | 'repeat' | 'brackets'
(default is'indices'
). Fix issues/22 and issues/23
Code example:
import xior, { encodeParams } from 'xior';
const filter = {
ids: [1, 2, 3],
dateFrom: new Date(),
dateTo: new Date(),
};
const http = xior.create({
paramsSerializer: (params: any) =>
encodeParams(params, true, null, {
allowDots: false,
arrayFormat: 'indices', // 'indices' | 'repeat' | 'brackets'
serializeDate: (date) => date.toISOString(),
}),
});
/*
'indices': { a: ['b', 'c'] } -> 'a[0]=b&a[1]=c'
'brackets': { a: ['b', 'c'] } -> 'a[]=b&a[]=c'
'repeat': { a: ['b', 'c'] } -> 'a=b&a=c'
*/
http.get('https://example.com', { params: { filter } });
- Feat(core): if request config
withCredentials: true
, before useless, now will set fetch configcredentials: 'include'
. Fix issues/19
This is a breaking change:
- Feat(core): The xior class should be CapitalCase like:
Xior
. Fix issues/18
If you always use import xior from 'xior';
, you can ignore migration code below.
Before:
import { xior } from 'xior';
Now:
import { Xior } from 'xior';
- Feat(new plugin): add token refresh plugin
- Feat: remove
undefined
value inparams
/data
Breaking Change
This version is about Axios compatible issue in some cases. Fixing #12 and #15.
- Feat(core): when
responseType: 'blob' | 'arrarybuffer'
then theresposne.data
isBlob
andArrayBuffer
, no needresponse.blob()
orresponse.arraybuffer()
anymore. - Fix(interceptors): make sure the multiple response interceptors chain behaviour same as axios's interceptors.
- Feat(plugin): add custom paramaters of LRU in plugins: cache, error-cache, throttle
- Feat(plugin): add
cacheTime
to cache plugin
- fix(plugin): fix error cache plugin
cacheTime
is undefined whenuseCacheFirst: true
- feat(plugin): error-cache plugin add cacheTime to the response
- feat(plugin):
error-retry
plugin'sretryInterval
addconfig
anderror
to parameters
- feat(core): add
try catch
toawait fetch(...)
Now you can capture the request error in response interceptors, and the error will be TypeError
:
import xior, { merge } from 'xior';
const http = xior.create({
// ...options
});
http.interceptors.response.use(
(result) => {
return result;
},
async (error) => {
if (error instanceof TypeError) {
console.log(`Request error:`, error);
}
if (error?.response?.status === 401) {
localStorage.removeItem('REQUEST_TOKEN');
}
}
);
- feat(plugins): enhance plugins's
enable*
logic
Now you can return undefined
in enable*
method:
import xior from 'xior';
import errorRetryPlugin from 'xior/plugins/error-retry';
const http = xior.create();
http.plugins.use(
errorRetryPlugin({
enableRetry(config, error) {
if (error.response?.status === 401) {
return false;
}
// no return here, and will reuse the default `enableRetry` logic
},
})
);
- feat(plugin): add
useCacheFirst
to error cache plugin
If
useCacheFirst: true
and there's a cache, it will return the cached response first, then run fetching in the background. This is useful when the response takes a long time, and the data is unnecessary in real-time.
- feat(plugin): add
onThrottle
to throttle plugin for logging purpose
- feat(plugin): add
onDedupe
to dedupe plugin for logging purpose
- feat: reduce build size use common
xior/utils
- chore: bump bunchee to v5.0.1
- fix(error-retry plugin): if have
request interceptors
, when error retry, retry with the latest request config fromrequest interceptors
- fix(core): POST/DELETE/PUT/PATCH methods when
content-type=application/x-www-form-urlencoded
, use formData to in body(previous put in url) - refactor(core): default request interceptors should work before send fetch
- refactor(core): remove
_data
in request config - refactor(core): remove
encode
in options, useparamsSerializer
option instead - chore(README): add encrypt/decrypt example to README
- fix(core): when post with
headers: { 'content-type': 'application/x-www-form-urlencoded' }
, shouldn't post with body - chore(core): shorter naming words
- fix(plugin): fix
error-retry
plugin default options override bugs - fix(plugin):
requestConfig
with plugins should always get latest config fromrequestinterceptors
- fix(plugin): fix
mock
plugin not working after bundle - chore(tests): refactor tests to use bundled files to run tests
- fix(plugin): fix
error-retry
plugin not working after bundle
- fix(plugin): fix
error-retry
plugin,TypeError
should retry too - feat(plugin):
error-retry
plugin,retryInterval
can befunction
too, and addonRetry
to options - chore(core): minor improvment
- feat(core): support direct call
xior.get/post..
similar toaxios.get/post..
API, no need create instance at first - fix(core):
DELETE
andOPTIONS
method's data option should be url encoded format likeGET
/HEAD
- feat: add
UMD
(Universal Module Definition) format bundle(now you can directly load xior in browser) - feat: add
VERSION
toxior
, now you can get current version of xior by:import xior from 'xior'; console.log(xior.VERSION)
- feat(new plugin): add
error-cache
plugin - feat(new plugin): add
dedupe
plugin - feat(new plugin): add
mock
plugin
Breaking Change:
- Type
before:
import xior from 'xior';
let instance: xior;
instance = xior.create();
Now:
import xior, { XiorInstance } from 'xior';
let instance: XiorInstance;
instance = xior.create();
- OPTIONS method
before:
import xior, { XiorInstance } from 'xior';
const instance = xior.create();
instance.options('/options_api_path', { text: 'this is data' }, { params: { a: 1 } });
now:
import xior, { XiorInstance } from 'xior';
const instance = xior.create();
instance.options('/options_api_path', { params: { a: 1, text: 'this is data' } });
- Feat(core): support
xiorInstance.defaults.headers['Authorization'] = 'Basic token';
- Feat(core): add
isGet?: boolean
option
- Feat(cache plugin): add
fromCache: boolean
in cache plugin
- Fix: compatiable
delete
method with axios, anddelete
method shouldn't have body - Chore: remove unused code in core module
Breaking change:
import xior from 'xior';
const http = xior.create({ baseURL: 'https://exampled.com' });
// before
http.delete('/', {}, { params: { a: 1, b: 2 } });
// now
http.delete('/', { params: { a: 1, b: 2 } });
- chore(build): Update build config to ensure consistency of plugin import paths
- chore(doc): Update README
- fix(plugins): resolve import plugins not found file error in expo(react-native) project
- feat(core): compatiable axios's options:
paramsSerializer
andwithCredentials
- feat(core): suport nested object paramaters in default
- feat(plugin): implemented error retry, cache, throttle, and upload/download progress plugins
- fix(build): resolved Bunchee build output error with Vite projects.
- chore(doc): updated README.md
- chore(examples): add bun, vite, and next build example for make sure it's working in these projects
- feat(plugin): Plugin mechanism implemented 🖖
- feat: Compatibility with polyfills in older environments
- fix: resolved issues with GitHub Actions release
- feat: support url as first paramter in xiorInstance.request('/url')
- feat: Removed first parameter
url
fromxiorInstance.request
- Chore: Enhanced README and added more tests
- Feat:
xiorInstance.request
remove first parameterurl
- Feat: improved error handling compatibility with Axios's response interceptor.
🐣