Fxios V3
中文版
Introductioninspired by axios, build with typescript, encapsulate origin fetch
fxios = fetch + axios
Usage
in browser
local install
npm install fxios// oryarn add fxios
default export an available instance
more to see: example.ts
create new instance
const f1 = config// orconst f2 = Fxios// orconst f3 = fxios
the config for create new instance is FxiosConfig
,data structure as below:
the request option will overwrite the instance config property as below
fxios.get
Instance Api
fxios#request(option: IFxiosRequestOption | string)
the option could be a string as below:
fxios.get'/api/users'
all other case,should use object option IFxiosRequestOption
,
as below:
fxios.post
IFxiosRequestOption data structure
these instance methods are all short cut of fxios#request
.
fxios#get
fxios#post
fxios#put
fxios#patch
fxios#delete
fxios#head
fxios#options
each method has already bind to the instance,need not to call like bind(fxios)
...get... // same as fxios.get(...)
path
is the parameter in the url path:
the below request will call this url: '/api/user/123/edit'。
fxios.get
when body is simple object, it will be JSON.stringify,and auto add {'Content-Type': 'application/json'}
to the request header,
other case, body will not be auto transformed.
as below:
fxios.post'/api/user',
Interceptor
each instance has interceptor
property,like transformRequest
and transformResponse
in axios.
interceptor has three property,request
、response
、catch
。
fxios.interceptor.request = fxios.interceptor.response = fxios.interceptor.catch =