All Projects → elbywan → Wretch Middlewares

elbywan / Wretch Middlewares

Licence: mit
Collection of middlewares for the Wretch library. 🎁

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Wretch Middlewares

Redux Query
A library for managing network state in Redux
Stars: ✭ 1,055 (+2411.9%)
Mutual labels:  middleware, fetch, request
Wretch
A tiny wrapper built around fetch with an intuitive syntax. 🍬
Stars: ✭ 2,285 (+5340.48%)
Mutual labels:  ajax, fetch, request
electron-request
Zero-dependency, Lightweight HTTP request client for Electron or Node.js
Stars: ✭ 45 (+7.14%)
Mutual labels:  fetch, ajax, request
vue-methods-promise
Let Vue methods support return Promise
Stars: ✭ 35 (-16.67%)
Mutual labels:  fetch, ajax, request
Gretchen
Making fetch happen in TypeScript.
Stars: ✭ 301 (+616.67%)
Mutual labels:  fetch, request
Thwack
A tiny modern data fetching solution
Stars: ✭ 268 (+538.1%)
Mutual labels:  ajax, fetch
Django Ajax
Fast and easy AJAX libraries for django applications. Contains ajax decorator, ajax middleware, shortcuts and more.
Stars: ✭ 312 (+642.86%)
Mutual labels:  middleware, ajax
Concurrency Logger
Log HTTP requests/responses separately, visualize their concurrency and report logs/errors in context of a request.
Stars: ✭ 400 (+852.38%)
Mutual labels:  middleware, request
react-redux-api-tools
A set of tools to facilitate react-redux development and decouple logic from compontents
Stars: ✭ 37 (-11.9%)
Mutual labels:  fetch, middleware
Redux Requests
Declarative AJAX requests and automatic network state management for single-page applications
Stars: ✭ 330 (+685.71%)
Mutual labels:  ajax, fetch
Ky Universal
Use Ky in both Node.js and browsers
Stars: ✭ 421 (+902.38%)
Mutual labels:  fetch, request
Cors
🔮Supported(Laravel/Lumen/PSR-15/Swoft/Slim/ThinkPHP) - PHP CORS (Cross-origin resource sharing) middleware.
Stars: ✭ 266 (+533.33%)
Mutual labels:  middleware, request
Trae
📮 Minimalistic Fetch based HTTP client
Stars: ✭ 257 (+511.9%)
Mutual labels:  fetch, request
Create Request
Apply interceptors to `fetch` and create a custom request function.
Stars: ✭ 34 (-19.05%)
Mutual labels:  fetch, request
Ky
🌳 Tiny & elegant JavaScript HTTP client based on the browser Fetch API
Stars: ✭ 7,047 (+16678.57%)
Mutual labels:  fetch, request
React Request
Declarative HTTP requests for React
Stars: ✭ 340 (+709.52%)
Mutual labels:  fetch, request
Unfetch
🐕 Bare minimum 500b fetch polyfill.
Stars: ✭ 5,239 (+12373.81%)
Mutual labels:  ajax, fetch
Ngx Restangular
Restangular for Angular 2 and higher versions
Stars: ✭ 787 (+1773.81%)
Mutual labels:  fetch, request
Xhr.js
🌎 xhr.js is a library(< 2Kb) to make AJAX/HTTP requests with XMLHttpRequest.
Stars: ✭ 12 (-71.43%)
Mutual labels:  ajax, fetch
axios-endpoints
Axios endpoints helps you to create a more concise endpoint mapping with axios.
Stars: ✭ 41 (-2.38%)
Mutual labels:  fetch, ajax

wretch-logo

Wretch middlewares

homepage-badge npm-badge license-badge

A collection of middlewares for the Wretch library.

Installation

Prerequisite: install Wretch

Npm

npm i wretch-middlewares

Cdn

<!-- Global variable name : window.wretchMiddlewares -->
<script src="https://unpkg.com/wretch-middlewares"></script>

Middlewares

Dedupe Retry  Throttling cache  Delay

Dedupe

Prevents having multiple identical requests on the fly at the same time.

Options

  • skip : (url, opts) => boolean

If skip returns true, then the dedupe check is skipped.

  • key : (url, opts) => string

Returns a key that is used to identify the request.

Usage

import wretch from 'wretch'
import { dedupe } from 'wretch-middlewares'

wretch().middlewares([
    dedupe({
        /* Options - defaults below */
        skip: (url, opts) => opts.skipDedupe || opts.method !== 'GET',
        key: (url, opts) => opts.method + '@' + url
    })
])./* ... */

Retry

Retries a request multiple times in case of an error (or until a custom condition is true).

Options

  • delayTimer : milliseconds

The timer between each attempt.

  • delayRamp : (delay, nbOfAttempts) => milliseconds

The custom function that is used to calculate the actual delay based on the the timer & the number of attemps.

  • maxAttempts : number

The maximum number of retries before resolving the promise with the last error. Specifying 0 means infinite retries.

  • until : (fetchResponse, error) => boolean | Promise<boolean>

The request will be retried until that condition is satisfied.

  • onRetry : ({ response, error, url, options }) => { url?, options? } || Promise<{url?, options?}>

Callback that will get executed before retrying the request. If this function returns an object having url and/or options properties, they will override existing values in the retried request. If it returns a Promise, it will be awaited before retrying the request.

  • retryOnNetworkError : boolean

If true, will retry the request if a network error was thrown. Will also provide an 'error' argument to the onRetry and until methods.

Usage

import wretch from 'wretch'
import { retry } from 'wretch-middlewares'

wretch().middlewares([
    retry({
        /* Options - defaults below */
        delayTimer: 500,
        delayRamp: (delay, nbOfAttempts) => delay * nbOfAttempts
        maxAttempts: 10,
        until: (response, error) => response && response.ok,
        onRetry: null,
        retryOnNetworkError: false
    })
])./* ... */

// You can also return a Promise, which is useful if you want to inspect the body:
wretch().middlewares([
    retry({
        until: response =>
            response.json().then(body =>
                body.field === 'something'
            )
    })
])

Throttling cache

A throttling cache which stores and serves server responses for a certain amount of time.

Options

  • throttle : milliseconds

The response will be stored for this amount of time before being deleted from the cache.

  • skip : (url, opts) => boolean

If skip returns true, then the dedupe check is skipped.

  • key : (url, opts) => string

Returns a key that is used to identify the request.

  • clear (url, opts) => boolean

Clears the cache if true.

  • invalidate (url, opts) => string | RegExp | Array<string | RegExp> | null

Removes url(s) matching the string or RegExp from the cache. Can use an array to invalidate multiple values.

  • condition response => boolean

If false then the response will not be added to the cache.

  • flagResponseOnCacheHit string

If set, a Response returned from the cache whill be flagged with a property name equal to this option.

Usage

import wretch from 'wretch'
import { throttlingCache } from 'wretch-middlewares'

wretch().middlewares([
    throttlingCache({
        /* Options - defaults below */
        throttle: 1000,
        skip: (url, opts) => opts.skipCache || opts.method !== 'GET',
        key: (url, opts) => opts.method + '@' + url,
        clear: (url, opts) => false,
        invalidate: (url, opts) => null,
        condition: response => response.ok,
        flagResponseOnCacheHit: '__cached'
    })
])./* ... */

Delay

Delays the request by a specific amount of time.

Options

  • time : milliseconds

The request will be delayed by that amount of time.

Usage

import wretch from 'wretch'
import { delay } from 'wretch-middlewares'

wretch().middlewares([
    delay(1000)
])./* ... */
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].