0.3.1 • Published 4 months ago

@tinkoff/request-plugin-prom-red-metrics v0.3.1

Weekly downloads
19
License
ISC
Repository
github
Last release
4 months ago

@tinkoff/request

Modular lightweight request library extendable by plugins.

Example of usage

import request from '@tinkoff/request-core';
import log from '@tinkoff/request-plugin-log';
import deduplicateCache from '@tinkoff/request-plugin-cache-deduplicate';
import memoryCache from '@tinkoff/request-plugin-cache-memory';
import persistentCache from '@tinkoff/request-plugin-cache-persistent';
import fallbackCache from '@tinkoff/request-plugin-cache-fallback';
import validate from '@tinkoff/request-plugin-validate';
import http from '@tinkoff/request-plugin-protocol-http';

const makeRequest = request([
    // The order of plugins is important
    log(), // log-plugin is first as we want it always execute
    deduplicateCache(), // plugins for cache are coming from simple one to complex as if simple cache has cached value - it will be returned and the others plugins won't be called
    memoryCache({ allowStale: true }), // passing parameters for specific plugin, see plugin docs
    persistentCache(),
    fallbackCache(), // fallbackCache is the last as it executed only for errored requests
    validate({
        validator: ({ response }) => {
            if (response.type === 'json') { return null; }
            return new Error('NOT json format');
        }
    }), // validate is placed exactly before plugin for actual request since there is no point to validate values from caches
    http() // on the last place the plugin to make actual request, it will be executed only if no plugin before changed the flow of request
]);

makeRequest({
    url: 'https://config.mysite.ru/resources?name=example'
})
    .then(result => console.log(result))
    .catch(error => console.error(error))

Plugins

Plugins can inject to the request flow to change its execution or adjust request\response data.

List of plugins

  1. protocol/http - base plugin to make request with http\https
  2. protocol/jsonp - plugin to make jsonp requests
  3. cache/deduplicate - deduplicate identical requests
  4. cache/memory - caches responses into memory
  5. cache/etag - !server only cache based on etag http-header
  6. cache/fallback - !server only stores response data to disk and returns from cache only for errored requests
  7. cache/persistent - !browser only caching data at IndexedDB to keep cache among page reloads
  8. log - logs the data of request execution
  9. batch - groups several request into single one
  10. validate - validate response or restore on errors
  11. transform-url - transforms url string for every request
  12. circuit-breaker - !server only fault protections
0.3.1

4 months ago

0.3.0

5 months ago

0.2.9

10 months ago

0.2.8

12 months ago

0.2.7

2 years ago

0.2.6

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.0-alpha.0

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.12

3 years ago

0.1.11

3 years ago

0.1.10

3 years ago

0.1.9

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago