1.1.6 • Published 5 years ago

egg-axios v1.1.6

Weekly downloads
44
License
MIT
Repository
github
Last release
5 years ago

egg-axios

axios plugin for Egg.js.

NOTE: This plugin just for integrate axios into Egg.js, more documentation please visit https://github.com/axios/axios.

Install

$ npm i --save egg-axios

Usage & configuration

  • config.default.js
exports.http = {
  headers: {
     common: {
        'Content-Type': 'application/json; charset=UTF-8'
       }
  },
 timeout: 10000
};
  • config/plugin.js
exports.http = {
  enable: true,
  package: 'egg-axios'
}

example

// controller.js or service.js
// with promise
this.ctx.http.get('/user', {id: 123}).then((data)=>{ // ==> /user?id=123
    // data is only remote server response data
    console.log(data);
}).catch((err)=>{
    console.error(err);
});
this.ctx.http.get('/user/:id', {id: 123}).then((data)=>{ // ==> /user/123
    // data is only remote server response data
    console.log(data);
}).catch((err)=>{
    console.error(err);
});
this.ctx.http.post('/post', {postId: 123}).then((data)=>{
    // data is only remote server response data
    console.log(data);
}).catch((err)=>{
    console.error(err);
});
// with await/async
try {
    const data = await this.ctx.http.get('/user', {id: 123});
    console.log(data);
} catch (e) {
    console.error(e)
}
try {
    const data = await this.ctx.http.post('/post', {postId: 123});
    console.log(data);
} catch (e) {
    console.error(e)
}

more example please visit https://github.com/axios/axios.

1.1.6

5 years ago

1.1.5

6 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago