Giter VIP home page Giter VIP logo

quickfetch's Introduction

QuickFetch

a fetch wrapper like axios, support middlewares & abort

1. How to install

npm i quickfetch --save

2. How to use

see test/QuickFetch.test.js

OR vue-cli-3-preset

to eliminate the "the request of a dependency is an expression" warning

about the issue

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;
})

3. API

Classes

QuickFetchMiddlewareHolder

QuickFetch

MiddlewareHolderEventTarget

MiddlewareHolder

Typedefs

option : Object | Null

an optional object for Request API

QuickFetch ⇐ MiddlewareHolder

QuickFetch

Kind: global class
Extends: MiddlewareHolder

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.ping(url, [params]) ⇒ boolean | 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

quickFetch._getMiddlewares(type, [option])

Kind: instance method of QuickFetch
Overrides: _getMiddlewares
Access: protected

Param Type Description
type String

QuickFetch.REQUEST

[option] Object

quickFetch._parseMiddlewares(mids, target, [params])

Kind: instance method of QuickFetch
Overrides: _parseMiddlewares
Access: protected

Param Type Default
mids Array
target Request | Response | JSON | Blob
[params] Object

quickFetch.use(type, middleware, [fetchId]) ⇒ 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 (req

[fetchId] string | number

a optional id for special requests

quickFetch._unuse(id)

Kind: instance method of QuickFetch
Overrides: _unuse
Access: protected

Param Type
id number

quickFetch._pause(id, [fetchId])

Kind: instance method of QuickFetch
Overrides: _pause
Access: protected

Param Type Description
id number
[fetchId] string | number

a optional id for special requests

quickFetch._resume(id, [fetchId])

Kind: instance method of QuickFetch
Overrides: _resume
Access: protected

Param Type Description
id number
[fetchId] string | number

a optional id for special requests

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._getMiddlewares(type, [option])

Kind: instance method of MiddlewareHolder
Access: protected

Param Type Description
type String

QuickFetch.REQUEST

[option] Object

middlewareHolder._parseMiddlewares(mids, target, [params])

Kind: instance method of MiddlewareHolder
Access: protected

Param Type Default
mids Array
target Request | Response | JSON | Blob
[params] Object

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

middleware function

a function looks like (req

[fetchId] string | number

a optional id for special requests

middlewareHolder._unuse(id)

Kind: instance method of MiddlewareHolder
Access: protected

Param Type
id number

middlewareHolder._pause(id, [fetchId])

Kind: instance method of MiddlewareHolder
Access: protected

Param Type Description
id number
[fetchId] string | number

a optional id for special requests

middlewareHolder._resume(id, [fetchId])

Kind: instance method of MiddlewareHolder
Access: protected

Param Type Description
id number
[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

[endpoint] string

optional, e.g. http://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

quickfetch's People

Contributors

tonylua avatar dependabot[bot] avatar

Stargazers

Wang Shuaibing avatar 猴头 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.