1.3.1 • Published 5 years ago

axios-container v1.3.1

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

Installing

Using npm:

$ npm install axios-container --save

Using cdn:

<script src="https://unpkg.com/axios-container"></script>

Import the package (after one of the options mentioned above):

import AxiosContainer from 'axios-container';
window.AxiosContainer = AxiosContainer;

Example

Basic usage

let axiosContainer = new AxiosContainer('/some/url');

// Create a request through the AxiosContainer
axiosContainer.createRequest('a_id', {
    parameter_1: 1,
    parameter_2: 2,
    // ...
}).then(function (response) {
    console.log(response);
}).catch(function (error) {
    console.log(error);
});

// Create another request through the AxiosContainer
axiosContainer.createRequest('b_id', {
    parameter_1: 1,
    parameter_2: 2,
    // ...
}).then(function (response) {
    console.log(response);
}).catch(function (error) {
    console.log(error);
});

// Both request will be bundled together into a single request.

/*
|--------------------------------------------------------------------------
| Response should be the following for the requests above
|--------------------------------------------------------------------------
|
| {
|   "a_id": "Response for 'a_id'",
|   "b_id": "Response for 'b_id'",
| }
|
*/

/*
|--------------------------------------------------------------------------
| `sendNow()`
|--------------------------------------------------------------------------
|
| You can call the `sendNow()` method on the container,
| if you would like to send the request instantly
| (not waiting for the intervalTime) 
|
*/
axiosContainer.sendNow();

Additional config

You can pass additional config to the AxiosContainer through the second parameter of the constructor.

let axiosContainer = new AxiosContainer('/some/url', {
    
    /*
    |--------------------------------------------------------------------------
    | method
    |--------------------------------------------------------------------------
    |
    | This request method to be used when making the request
    |
    */
    method: 'GET',
    
    /*
    |--------------------------------------------------------------------------
    | intervalTime
    |--------------------------------------------------------------------------
    |
    | This time to be waited after the last `createRequest` call
    | before sending the axios request.
    |
    | If set to `false`, the request will be sent only if
    | the `sendNow()` method is called.
    |
    */
    intervalTime: 5000,
    
    /*
    |--------------------------------------------------------------------------
    | data
    |--------------------------------------------------------------------------
    |
    | This object's content to be sent with each request
    | (extending the request's `data` axios parameter)
    |
    */
    data: {},
    
    /*
    |--------------------------------------------------------------------------
    | axiosConfig
    |--------------------------------------------------------------------------
    |
    | This config to be added to each axios request
    |
    */
    axiosConfig: {},
    
    /*
    |--------------------------------------------------------------------------
    | noCache
    |--------------------------------------------------------------------------
    |
    | If a request was made before with the same ID,
    | it will return the previous request's response
    | (without making one more)
    |
    */
    noCache: false
    
});
1.3.1

5 years ago

1.3.0

6 years ago

1.2.0

6 years ago

1.1.10

6 years ago

1.1.9

6 years ago

1.1.8

6 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago