2.0.0 • Published 4 years ago

@deleteagency/axios-singular v2.0.0

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

Axios Singular

Live Demo

Motivation

TODO About parallel request and not guaranteed order of receiving reponses

Installation

Use the package manager npm for installation.

$ npm install @deleteagency/axios-singular

Usage

import axios from  'axios';
import AxiosSingular from  '@deleteagency/axios-singular';

const instance = new AxiosSingular(axios);

instance.get("/posts")
    .then((response) => {
        console.log(response)
    },() => {
        if (axios.isCancel(error)) {
            console.log('Request canceled' , error)
        }else{
            console.error('Actual error!' , error)
        }
    })

API

constructor(axiosInstance, CancelToken, isCancel)

Returns AxiosSingular.

In order to use custom axios instance you have to pass CancelToken and isCancel as additional arguments. That's because custom instances don't have all base axios properties. Read this comment: https://github.com/axios/axios/issues/1330#issuecomment-362846633

axiosInstance

Required Type: object

Default or any custom axios instance. See details here: https://github.com/axios/axios#creating-an-instance

CancelToken

Optional Type: object

CancelToken from the base axios instance

isCancel

Optional Type: Function

isCancel from the base axios instance

get(...) (request, delete, head, options, post, put, patch)

Returns Promise.

Corresponding axios methos is called under the hood with all arguments bypassed. Supported methods: request, get, delete, head, options, post, put, patch See https://github.com/axios/axios#request-method-aliases

cancel(reason)

Cancel current request if it is in progress

License

MIT

2.0.0

4 years ago

2.0.0-1

5 years ago

2.0.0-0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago