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