Gathering detailed insights and metrics for egg-axios-plus
Gathering detailed insights and metrics for egg-axios-plus
Gathering detailed insights and metrics for egg-axios-plus
Gathering detailed insights and metrics for egg-axios-plus
eggjs框架中单纯的用curl来请求http服务难免出现重复的代码,不利于开发效率的提高;egg-axios-plus实在axios插件的封装基础上完美兼容eggjs框架,满足常用的Get、Post、Delete、Put等请求;
npm install egg-axios-plus
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
3 Stars
23 Commits
1 Forks
1 Watchers
1 Branches
1 Contributors
Updated on Aug 22, 2024
Latest Version
3.1.3
Package Id
egg-axios-plus@3.1.3
Unpacked Size
36.30 kB
Size
10.26 kB
File Count
10
NPM Version
6.14.17
Node Version
14.19.2
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
egg-axios-plus is based on the axios plug-in, it is applicable to the basic HTTP request of the egg framework, and satisfies the async / await operation. Welcome to use the plug-in to learn more properties and functions
1$ npm install egg-axios-plus --save
1// {app_root}/config/plugin.js 2exports.axiosPlus = { 3 enable: true, 4 package: 'egg-axios-plus', 5};
1// {app_root}/config/config.default.js 2exports.axiosPlus = { 3 // can set more config in headers,like token,references and so on 4 headers: { 5 common: { 6 'Content-Type': 'application/json; charset=UTF-8', 7 // 添加认证【例如】,也可以在请求拦截器中修改具体的request config 8 // 'Authorization':'19980115_520' // 不要问我19980115是什么,当然是女朋友生日呀!!! 9 }, 10 // 可以设置请求头等属性 11 }, 12 // 定义请求拦截器处理方法【可选】 13 // requestInterceptorsHandler: config => { 14 // // 请求之前的配置信息 15 // // 当该字段【函数】不存在是,默认如下: 16 // app.coreLogger.debug(`[egg-axios-plus] send request, baseURL: ${JSON.stringify(config.baseURL)}, url: ${config.url}, method: ${config.method}, data: ${JSON.stringify(config.data)}, headers: ${JSON.stringify(config.headers)}`); 17 // return config; 18 // }, 19 // requestInterceptorsErrorHandler: error => { 20 // // 请求之后发生的错误信息 21 // // 当该字段【函数】不存在是,默认如下: 22 // app.coreLogger.error(`[egg-axios-plus] send request error, ${error.message}`); 23 // return Promise.reject(error); 24 // }, 25 // // 定义axios响应拦截器处理方法【可选】 26 // responseInterceptorsHandler: response => { 27 // // response 响应结果 28 // // 当该字段【函数】不存在是,默认如下: 29 // app.coreLogger.debug(`[egg-axios-plus] receive response, data: ${JSON.stringify(response.data)}, status: ${response.status}, headers: ${JSON.stringify(response.headers)}`); 30 // if (response.config && (response.config.method.toUpperCase() === 'HEAD' || response.config.method.toUpperCase() === 'options')) { 31 // return response; 32 // } 33 // return response.data; 34 // }, 35 // responseInterceptorsErrorHandler: error => { 36 // // 接口响应失败的错误结果 37 // // 当该字段【函数】不存在是,默认如下: 38 // app.coreLogger.error(`[egg-axios-plus] receive response error, ${error.message}`); 39 // return Promise.reject(error); 40 // }, 41 timeout: 5000, // 默认请求超时 42 app: true, // 在app.js上启动加载 43 agent: false, // 在agent.js上启动加载 44};
if you want to use axios in agent or app , you can set config about agent or app ,make them be ture
1exports.axiosPlus = { 2 app: true, 3 agent: true 4}
see config/config.default.js for more detail default config.
|Type|Support| |:--:|:--:| |GET|✔| |DELETE|✔| |HEAD|✔| |OPTIONS|✔| |PUT|✔| |POST|✔| |PATCH|✔|
If you want to learn about learning the plug-in of egg-axios-plus, we strongly recommend that you learn the Axios and Eggjs framework. As the name implies, this plug-in needs to be applied in the egg project. Let's start to write the sample code
1// you can write request code by egg-axios-plus in controller.js or service.js 2 3// supprt get 4this.ctx.axios.get("request url", { 5 // parameters object 6}).then(callbackData => { 7 //gain this data is only remote server response data by callback method 8 console.log(callbackData); 9 // add code to deal with the data from get request 10}).catch(err => { 11 // If there is an error in the request,it will be caught here 12 console.log(err) 13}) 14 15// support post 16this.ctx.axios.post("request url", { 17 // parameters object 18}).then(callbackData => { 19 console.log(callbackData); 20}).catch(err => { 21 console.log(err) 22}) 23// support put,delete and other common type request ,just write like uper code;
If you don't want to use the callback function to get the result of the request in the code process, egg-axios-plus can also support the way to synchronously get the request with async/await . But keep vigilant that the parent method that used axios must be async
1try { 2 const responseData = await this.ctx.axios.get('request url', { 3 // parameters object 4 }); 5 // add code to operate data with await 6 console.log(responseData); 7} catch (err) { 8 console.log(err) 9}
Requests can be made by passing the relevant config to axios
.
1// Send a POST request 2this.ctx.axios({ 3 method: 'post', 4 url: '/user/12345', 5 data: { 6 firstName: 'Fred', 7 lastName: 'Flintstone' 8 } 9}); 10// GET request for remote image 11this.ctx.axios({ 12 method: 'get', 13 url: 'http://bit.ly/2mTM3nY', 14 responseType: 'stream' 15}).then(response => { 16 console.log(response); 17});
For convenience aliases have been provided for all supported request methods.
this.ctx.axios.request(config)
this.ctx.axios.get(url[, config])
this.ctx.axios.delete(url[, config])
this.ctx.axios.head(url[, config])
this.ctx.axios.options(url[, config])
this.ctx.axios.post(url[, data[, config]])
this.ctx.axios.put(url[, data[, config]])
this.ctx.axios.patch(url[, data[, config]])
When using the alias methods url
, method
, and data
properties don't need to be specified in config.
You can specify config defaults that will be applied to every request.
1const axios = this.ctx.axios; 2axios.defaults.baseURL = 'https://api.example.com'; 3axios.defaults.headers.common['Authorization'] = AUTH_TOKEN; 4axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
1// Set config defaults when creating the instance 2const instance = axios.create({ 3 baseURL: 'https://api.example.com' 4}); 5// Alter defaults after instance has been created 6instance.defaults.headers.common['Authorization'] = AUTH_TOKEN;
Config will be merged with an order of precedence. The order is library defaults found
in lib/defaults.js, then defaults
property of the
instance, and finally config
argument for the request. The latter will take precedence over the former. Here's an
example.
1// Create an instance using the config defaults provided by the library 2// At this point the timeout config value is `0` as is the default for the library 3const instance = axios.create(); 4// Override timeout default for the library 5// Now all requests using this instance will wait 2.5 seconds before timing out 6instance.defaults.timeout = 2500; 7// Override timeout for this request as it's known to take a long time 8instance.get('/longRequest', { 9 timeout: 5000 10});
more example please visit https://github.com/axios/axios or contact with Taylor
Please open an issue here.
1MIT License 2 3Copyright (c) 2022 142vip FairySister Rong姐姐好可爱 4 5Permission is hereby granted, free of charge, to any person obtaining a copy 6of this software and associated documentation files (the "Software"), to deal 7in the Software without restriction, including without limitation the rights 8to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9copies of the Software, and to permit persons to whom the Software is 10furnished to do so, subject to the following conditions: 11 12The above copyright notice and this permission notice shall be included in all 13copies or substantial portions of the Software. 14 15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21SOFTWARE.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/14 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More