1.0.1 • Published 7 years ago

axios-request-manager v1.0.1

Weekly downloads
4
License
Apache-2.0
Repository
github
Last release
7 years ago

Axios Request manager

Build Status Coverage Status David David

Manager that creates and stores Axios Cancel tokens. For more information on Axios Cancel tokens, please read the following Axios documentation

Installing

Using npm:

$ npm install axios-request-manager

Examples

Create and cancel a single Axios request:

import axios from 'axios';
import RequestManager from 'request-manager';

const manager = new RequestManager();
const cancelToken = manager.getNextToken('users');

axios.get('/api/users', { cancelToken });
manager.cancelAxios('users', 'User aborted the operation');

You can also group your requests and cancel them all in once using the cancel key prefix:

import axios from 'axios';
import RequestManager from 'request-manager';

const manager = new RequestManager();
const getCancelToken = manager.getNextToken('users/get');
const putCancelToken = manager.getNextToken('users/put');

axios.get('/api/users', { cancelToken: getCancelToken });
axios.put('/api/users', { cancelToken: putCancelToken });

manager.cancelAllRequestsWithPrefix('users');

If you have an autosave feature on your forms you can cancel previous requests and execute a new ones like so:

import axios from 'axios';
import RequestManager from 'request-manager';

const manager = new RequestManager();
const cancelToken = manager.cancelAxiosAndGetNextToken('form/save');

axios.get('/api/form', { cancelToken });

License

Copyright 2016 KAYAK Germany, GmbH

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Crafted with ♥ in Berlin.