JSPM

axios-rest-wrapper

0.0.3
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 26
  • Score
    100M100P100Q33612F
  • License ISC

Wraper axios as rest client and fix BUGS!

Package Exports

  • axios-rest-wrapper

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (axios-rest-wrapper) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

axios-rest-wrapper

Wrap axios as REST client

Fixes in axios version 0.18

  1. fix interceptors order bug
  2. axios.get with params not working like my expect
axios.get('/hello', {params: { 'isGoodDay': 'no' })
// it should send request with /hello?isGoodDay=no
// but in current version(0.18) it just send request to /hello

Installation

npm install axios-rest-wrapper

Example

// create API instance, yes I just pass the arguments to axios.create()
const API = AxiosRestWrapper({
  baseURL: process.env.SOMEWHERE,
  interceptors: {
    // using this syntax arugment to fix interceptors reverse order issue in version 0.18.
    request: [
      [function(config) {
        return config
      }, function (error) {
        return Promise.reject(error)
      }]
    ]
  },
  restResources: {
    user: {
      prefix: 'users', // required
      key: 'id', // optional
      instanceMethods : { // optional, usage below
        mudamuda: function() {
          return false
        }
      },
      classMethods : { // optional, usage below
        wryyyyyy: function() {
          return 'raod rolla  daaaaaaaaaaaa!!'
        }
      }
    }
  }
})

API.user.wryyyyyy()
// 'raod rolla  daaaaaaaaaaaa!!'

user = API.user.find(1)
// send GET request to /users/1

user.mudamuda()
// false

user.update({yeee: ''})
// PUT /users/1 with body {yeee: ''}

Contribution

We don't have delete method and nested resource support now.