CRITICAL
Rule Definition
When designing web service to get/put/post data, you want to make sure that you minimize the number of calls between the client application and web service server. By minimizing the number of calls, you improve application speed, reduce communications overhead (why send three requests when you can do it by one), and reduce network traffic.
Remediation
The web-services should not be called inside a loop.
Try to handle the logic in such a way that the call is made outside the web-service and data fetch, write etc is handled with a variable or an array.
Violation Code Sample
<script>
mounted() {
for (i = 0; i < this.test_array.length; i++){
.
.
.
axios({ method: "GET", "url": "https://httpbin.org/ip" }).then(result => {
this.ip = result.data.origin;
}, error => {
console.error(error);
});
}
},
methods: { }
</script>
Fixed Code Sample
<script>
mounted() {
axios({ method: "GET", "url": "https://httpbin.org/ip" }).then(result => {
this.ip = result.data.origin;
}, error => {
console.error(error);
});
},
methods: { }
</script>
Reference
CISQ Rule: ASCPEM-PRF-08
Related Technologies
Technical Criterion
CWE-1050 - Excessive Platform Resource Consumption within a Loop
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.