Navel Pondering Mantra

    axiosbluebird

    1.1.10 • Public • Published

    axiosBluebird

    Axios with Promise (Bluebird) cancelation

    NODE: v10.15.1

    NPM: v6.4.1

    How to use - get

    const axiosBluebird = require("axiosbluebird")
    const Promise = axiosBluebird.Promise
    let retrieveDataRequest = Promise.resolve()
    
    const retrieveData = (url, params) => {
      retrieveDataRequest.cancel()
      retrieveDataRequest = axiosBluebird.get(url, params)
      return retrieveDataRequest
        .then(json => json.data)
        .catch(console.error.bind(console, "FAIL - retrieveData:"))
    }
    retrieveData('http://api.sylo.space/api/valtech/cases', {id: 17})
    retrieveData('http://api.sylo.space/api/valtech/cases?id=40', {id: [1,2,3]}) // previous progressing queue will cancel
      .then(console.log.bind(console))

    How to use - axios

    Parameters as Object in axios documentation

    Parameters as String not supported

    const axiosBluebird = require("axiosbluebird")
    const Promise = axiosBluebird.Promise
    let axiosDataRequest = Promise.resolve()
    
    const axiosData = requestConfig => {
      axiosDataRequest.cancel()
      axiosDataRequest = axiosBluebird.axios(requestConfig)
      return axiosDataRequest
        .catch(console.error.bind(console, "FAIL - axiosData:"))
    }
    // 1st request
    axiosData({
      method: "post",
      url: "/user/12345",
      data: {
        firstName: "Fred",
        lastName: "Flintstone"
      }
    })
    
    // 2nd request
    axiosData({
      method: "get",
      url: "http://bit.ly/2mTM3nY",
      responseType: "stream" })
        .then(response => response.data.pipe(fs.createWriteStream("ada_lovelace.jpg"))
    ) // previous progressing queue will be canceled

    responseType: 'stream' not yet tested

    Methods

    Promise: Bluebird Promise with Cancelation enabled

    axios ( requestConfig: Object ): Request with configuration


    delete ( url: String [, params: Object] ): Axios request with DELETE method

    get ( url: String [, params: Object] ): Axios request with GET method

    head ( url: String [, params: Object] ): Axios request with HEAD method

    options ( url: String [, params: Object] ): Axios request with OPTIONS method


    post ( url: String, params: Object ): Axios request with POST method

    put ( url: String, params: Object ): Axios request with PUT method

    patch ( url: String, params: Object ): Axios request with PATCH method

    NOTE!

    Param properties as array

    params: {
      filter: [8, 16, 32]
    }

    will output:

    filter=8&filter=16&filter=32
    

    Idealisticly:

    filter=[8,16,32]
    

    But some servers can't accept brackets

    Install

    npm i axiosbluebird

    DownloadsWeekly Downloads

    7

    Version

    1.1.10

    License

    MIT

    Unpacked Size

    13.1 kB

    Total Files

    14

    Last publish

    Collaborators

    • harianto