server/database/download-victim-data.js
// Retrieve Victim Data for the United States
Retrieve Victim Data for the United States
Retrieve Victim Data for the United States
function downloadAllVictimData() {
  for(let i = 0; i < variables.length; i++) {
    let offense = offenses[i];
    let variable = variables[i];
    for(let j = 0; j < offenses.length; j++) {
      let offense = offenses[j];
      return axios({
        method:'get',
        url:`https://api.usa.gov/crime/fbi/sapi/api/nibrs/${offense}/victim/national/${variable}?api_key=iiHnOKfno2Mgkt5AynpvPpUQTEyxE77jo1RU8PIv`,
        responseType:'stream'
      })
      .then((response) => {
        response.data.pipe(fs.createWriteStream(`/Users/jefflewis/Documents/Computer-Programming/Projects/Converted GraphQL REST APIs/fbi-crime-data-rest-api-to-graphql/database/victim-data/all-united-states/${offense}/${offense}-by-${variable}.json`))
      })
      .then(console.log("Offense: ", offense))
      .catch((error) => console.log(error));
    }
  }
}
function downloadAllVictimData ( ) { for ( let i = 0 ; i < variables . length ; i ++ ) { let offense = offenses [ i ] ; let variable = variables [ i ] ; for ( let j = 0 ; j < offenses . length ; j ++ ) { let offense = offenses [ j ] ; return axios ( { method : 'get' , url : ` ${ offense } ${ variable } ` , responseType : 'stream' } ) . then ( ( response ) => { response . data . pipe ( fs . createWriteStream ( ` ${ offense } ${ offense } ${ variable } ` ) ) } ) . then ( console . log ( "Offense: " , offense ) ) . catch ( ( error ) => console . log ( error ) ) ; } } }
Retrieve Victim Data for the United States
Retrieve Victim Data for the United States
// Iterate through the Variables // Iterate through the Offenses // Axios: GET Request // Write response to .json file and store in the database // Error Handling