quickfetch v1.0.0-alpha.5
QuickFetch
a fetch wrapper like axios, support middlewares & abort
1. How to install
npm i quickfetch --save2. How to use
see test/QuickFetch.test.js
3. API
Classes
Typedefs
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>
- .use(type, middleware, [fetchId]) ⇒ object
- static
new QuickFetch(option)
a fetch-based HTTP request tool
| Param | Type |
|---|---|
| option | option |
quickFetch.get(url, params, option) ⇒ Promise
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 |
quickFetch.post(url, params, option) ⇒ Promise
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 |
quickFetch.delete(url, params, option) ⇒ Promise
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 |
quickFetch.put(url, params, option) ⇒ Promise
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 |
quickFetch.patch(url, params, option) ⇒ Promise
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 |
quickFetch.sequence(requestPromiseArr) ⇒ Array.<Response>
make batch requests
Kind: instance method of QuickFetch
| Param | Type |
|---|---|
| requestPromiseArr | Array.<Promise> |
quickFetch.use(type, middleware, fetchId) ⇒ object
regist a middleware
Kind: instance method of QuickFetch
Returns: object - actions - { unuse, pause, resume }
| Param | Type | Description | ||
|---|---|---|---|---|
| type | string | QuickFetch.REQUEST | QuickFetch.RESPONSE | QuickFetch.ERROR |
| middleware | function | a function looks like (req|res|err, next) => {} | ||
| fetchId | string | number | a optional id for special requests |
QuickFetch.REQUEST
Kind: static property of QuickFetch
QuickFetch.RESPONSE
Kind: static property of QuickFetch
QuickFetch.ERROR
Kind: static property of QuickFetch
QuickFetch.EXCEPTION_TIMEOUT
Kind: static property of QuickFetch
QuickFetch.EVENT_FETCH_ABORT
Kind: static property of QuickFetch
QuickFetch.abort(id)
cancel a fetch action
Kind: static method of QuickFetch
| Param | Type | Description |
|---|---|---|
| id | string | number | symbol | fetchId |
MiddlewareHolder ⇐ EventTarget
MiddlewareHolder
Kind: global class
Extends: EventTarget
middlewareHolder.use(type, middleware, fetchId) ⇒ object
regist a middleware
Kind: instance method of MiddlewareHolder
Returns: object - actions - { unuse, pause, resume }
| Param | Type | Description | ||
|---|---|---|---|---|
| type | string | QuickFetch.REQUEST | QuickFetch.RESPONSE | QuickFetch.ERROR |
| middleware | function | a function looks like (req|res|err, next) => {} | ||
| fetchId | string | number | a optional id for special requests |
option : Object | Null
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 | |
| baseURL | string | optional, an url prefix | |
| 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 |
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago