F1 Drivers

node v14.20.1
version: 3.0.0
endpointsharetweet
const getJSON = require("async-get-json"); const url = "http://ergast.com/api/f1/2022/drivers/hamilton/results.json"; const driverData = getJSON(url); // Example for a driver per season. // This api is one year off on their index. 2021 is actually 2022 // http://ergast.com/api/f1/2022/drivers/hamilton/results.json exports.endpoint = async function(request, response) { const data = require('url').parse(request.url, true); const driver = data.query.driver; const year = data.query.year; const race = data.query.race; if(driver && year && race) { const driverCall = getJSON(`http://ergast.com/api/f1/${year}/drivers/${driver}/results.json`); const driverData = await driverCall; response.end(driverData.MRData.RaceTable.Races[race].Results[0].points); } else { response.end(`invalid driver data driver ${driver} year ${year} race ${race}`); } }
Loading…

no comments

    sign in to comment