Installing
Using npm:
$ npm install axios-container --save
Using cdn:
Import the package (after one of the options mentioned above):
;windowAxiosContainer = AxiosContainer;
Example
Basic usage
let axiosContainer = '/some/url'; // Create a request through the AxiosContaineraxiosContainer; // Create another request through the AxiosContaineraxiosContainer; // 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;
Additional config
You can pass additional config to the AxiosContainer
through the second parameter of the constructor.
let 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 ;