a fetch wrapper like axios, support middlewares & abort
npm i quickfetch --save
see test/QuickFetch.test.js
add below to your webpack config:
// quickfetch uses parcel-bundler which has require statements
new webpack.ContextReplacementPlugin(/quickfetch/, data => {
delete data.dependencies[0].critical;
return data;
})
- QuickFetch ⇐
MiddlewareHolder
QuickFetch
- MiddlewareHolder ⇐
EventTarget
MiddlewareHolder
- option :
Object
|Null
an optional object for Request API
QuickFetch ⇐ MiddlewareHolder
QuickFetch
Kind: global class
Extends: MiddlewareHolder
- QuickFetch ⇐
MiddlewareHolder
- new QuickFetch([option])
- instance
- .get(url, [params], [option]) ⇒
Promise
- .post(url, [params], [option]) ⇒
Promise
- .delete(url, [params], [option]) ⇒
Promise
- .put(url, [params], [option]) ⇒
Promise
- .patch(url, [params], [option]) ⇒
Promise
- .sequence(requestPromiseArr) ⇒
Array.<Response>
- .ping(url, [params]) ⇒
boolean
|Promise
- ._getMiddlewares(type, [option])
- ._parseMiddlewares(mids, target, [params])
- .use(type, middleware, [fetchId]) ⇒
object
- ._unuse(id)
- ._pause(id, [fetchId])
- ._resume(id, [fetchId])
- .get(url, [params], [option]) ⇒
- static
a fetch-based HTTP request tool
Param | Type |
---|---|
[option] | option |
make a GET fetch
Kind: instance method of QuickFetch
Returns: Promise
-
a Promise that resolves to a Response object
See: QuickFetch#constuctor
Param | Type | Description |
---|---|---|
url | string |
|
[params] | Object | null |
an optional params object |
[option] | option |
make a POST fetch
Kind: instance method of QuickFetch
Returns: Promise
-
a Promise that resolves to a Response object
Param | Type | Description |
---|---|---|
url | string |
|
[params] | Object | null |
an optional params object |
[option] | option |
make a DELETE fetch
Kind: instance method of QuickFetch
Returns: Promise
-
a Promise that resolves to a Response object
Param | Type | Description |
---|---|---|
url | string |
|
[params] | Object | null |
an optional params object |
[option] | option |
make a PUT fetch
Kind: instance method of QuickFetch
Returns: Promise
-
a Promise that resolves to a Response object
Param | Type | Description |
---|---|---|
url | string |
|
[params] | Object | null |
an optional params object |
[option] | option |
make a PATCH fetch
Kind: instance method of QuickFetch
Returns: Promise
-
a Promise that resolves to a Response object
Param | Type | Description |
---|---|---|
url | string |
|
[params] | Object | null |
an optional params object |
[option] | option |
make batch requests
Kind: instance method of QuickFetch
Param | Type |
---|---|
requestPromiseArr | Array.<Promise> |
send a beacon
Kind: instance method of QuickFetch
Returns: boolean
| Promise
-
send result
Param | Type | Description |
---|---|---|
url | string |
|
[params] | Object | null |
an optional params object |
Kind: instance method of QuickFetch
Overrides: _getMiddlewares
Access: protected
Param | Type | Description |
---|---|---|
type | String |
QuickFetch.REQUEST |
[option] | Object |
Kind: instance method of QuickFetch
Overrides: _parseMiddlewares
Access: protected
Param | Type | Default |
---|---|---|
mids | Array |
|
target | Request | Response | JSON | Blob |
|
[params] | Object |
|
regist a middleware
Kind: instance method of QuickFetch
Overrides: use
Returns: object
-
actions - { unuse, pause, resume }
Param | Type | Description |
---|---|---|
type | string |
QuickFetch.REQUEST |
middleware | function |
a function looks like |
[fetchId] | string | number |
a optional id for special requests |
Kind: instance method of QuickFetch
Overrides: _unuse
Access: protected
Param | Type |
---|---|
id | number |
Kind: instance method of QuickFetch
Overrides: _pause
Access: protected
Param | Type | Description |
---|---|---|
id | number |
|
[fetchId] | string | number |
a optional id for special requests |
Kind: instance method of QuickFetch
Overrides: _resume
Access: protected
Param | Type | Description |
---|---|---|
id | number |
|
[fetchId] | string | number |
a optional id for special requests |
cancel a fetch action
Kind: static method of QuickFetch
Param | Type | Description |
---|---|---|
id | string | number | symbol |
fetchId |
MiddlewareHolder
Kind: global class
Extends: EventTarget
- MiddlewareHolder ⇐
EventTarget
Kind: instance method of MiddlewareHolder
Access: protected
Param | Type | Description |
---|---|---|
type | String |
QuickFetch.REQUEST |
[option] | Object |
Kind: instance method of MiddlewareHolder
Access: protected
Param | Type | Default |
---|---|---|
mids | Array |
|
target | Request | Response | JSON | Blob |
|
[params] | Object |
|
regist a middleware
Kind: instance method of MiddlewareHolder
Returns: object
-
actions - { unuse, pause, resume }
Param | Type | Description |
---|---|---|
type | string |
QuickFetch.REQUEST |
middleware | function |
a function looks like |
[fetchId] | string | number |
a optional id for special requests |
Kind: instance method of MiddlewareHolder
Access: protected
Param | Type |
---|---|
id | number |
Kind: instance method of MiddlewareHolder
Access: protected
Param | Type | Description |
---|---|---|
id | number |
|
[fetchId] | string | number |
a optional id for special requests |
Kind: instance method of MiddlewareHolder
Access: protected
Param | Type | Description |
---|---|---|
id | number |
|
[fetchId] | string | number |
a optional id for special requests |
an optional object for Request API
Kind: global typedef
Properties
Name | Type | Default | Description |
---|---|---|---|
[method] | string |
standard fetch init option |
|
[credentials] | string |
"include" |
standard fetch init option |
[mode] | string |
"cors" |
standard fetch init option |
[cache] | string |
"reload" |
standard fetch init option |
[headers] | Object |
standard fetch init option |
|
[endpoint] | string |
optional, e.g. https://xxx.com:8090 |
|
[baseURL] | string |
optional, an url prefix, e.g. /myapi |
|
[timeout] | string |
30000 |
optional, timeout |
[catchError] | boolean |
true |
optional, if true then just parse error in middleware, otherwise throw it to endpoint |
[ignoreBodyMethods] | Array |
['get', 'head'] |
optional |
[forceJSON] | boolean |
false |
optional, send body with JSON.stringify() |
[fetchId] | string | number | symbol |
optional, an unique ID of every fetch request |
|
[signal] | AbortSignal |
optional, a given signal to cancel the fetch request |