server/database/download-police-employment-data.js
// Retrieve Police Employment Data for the United States
Retrieve Police Employment Data for the United States
Retrieve Police Employment Data for the United States
function downloadAllPoliceEmploymentDataByRegion() {
  for(let i = 0; i < regions.length; i++) {
    let region = regions[i];
    axios({
      method:'get',
      url:`https://api.usa.gov/crime/fbi/sapi/api/police-employment/regions/${region}/?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/employment-data/police-employment/regions/${region}-police-employment.json`))
    })
    .catch((error) => console.log(error));
  }
}
function downloadAllPoliceEmploymentDataByRegion ( ) { for ( let i = 0 ; i < regions . length ; i ++ ) { let region = regions [ i ] ; axios ( { method : 'get' , url : ` ${ region } ` , responseType : 'stream' } ) . then ( ( response ) => { response . data . pipe ( fs . createWriteStream ( ` ${ region } ` ) ) } ) . catch ( ( error ) => console . log ( error ) ) ; } }
Retrieve Police Employment Data for the United States
Retrieve Police Employment Data for the United States
// Iterate through the Regions // Axios: GET Request // Write response to .json file and store in the database // Error Handling // Set Timeout ()