I have implemented cloud code in ParseServer - Back4app, which utilizes node.js to send a request for Football API. The axios request returned the following result:
{
"result": {
"get": "teams",
"parameters": {
"country": "brazil"
},
"errors": [],
"results": 785,
"paging": {
"current": 1,
"total": 1
},
"response": [
{
"team": {
"id": 6,
"name": "Brazil",
"code": "BRA",
"country": "Brazil",
"founded": 1914,
"national": true,
"logo": "https://media.api-sports.io/football/teams/6.png"
},
"venue": {
"id": 204,
"name": "Estadio Jornalista Mário Filho (Maracanã)",
"address": "Rua Professor Eurico Rabelo, Maracanã",
"city": "Rio de Janeiro, Rio de Janeiro",
"capacity": 78838,
"surface": "grass",
"image": "https://media.api-sports.io/football/venues/204.png"
}
},
{
"team": {
"id": 118,
"name": "Bahia",
"code": "BAH",
"country": "Brazil",
"founded": 1931,
"national": false,
"logo": "https://media.api-sports.io/football/teams/118.png"
},
"venue": {
"id": 216,
"name": "Arena Fonte Nova",
"address": "Rua Lions Club, Nazaré",
"city": "Salvador, Bahia",
"capacity": 56500,
"surface": "grass",
"image": "https://media.api-sports.io/football/venues/216.png"
}
}, (repeat for more 783 X)
What is the most efficient way to loop through the response data and extract all "teams" and their corresponding "venues" names, ids, addresses, etc. using JavaScript?
I have attempted various methods, but unfortunately none of them have been successful for me.
Here's an example of my current code:
Parse.Cloud.define("teams", (request)=>{
const axios = require("axios");
const time = request.params.time;
const options = {
method: 'GET',
url: 'https://api-football-v1.p.rapidapi.com/v3/teams',
params: {country:'brazil'},
headers: {
'X-RapidAPI-Key': 'd69302225emshdf770c890926efdp19ca04jsn08d2244e2253',
'X-RapidAPI-Host': 'api-football-v1.p.rapidapi.com',
}
};
var resultado = axios.request(options).then( function (response) {
return (response.data);
// return "olá função "
}).catch(function (error) {
return("erro meu nobre!");
});
return resultado;