axios-rest-wrapper
v0.0.3
Published
Wraper axios as rest client and fix BUGS!
Downloads
6
Readme
axios-rest-wrapper
Wrap axios as REST client
Fixes in axios version 0.18
- fix interceptors order bug
- 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.