I am attempting to make an API which given an address will return a JSON with all the information in my database about it.
The API call looks like this /api/allinformation?string=_+400+kent+st+brooklyn+ny+11214
app.get("/api/allinformation", function (req, res) {
let params = req.originalUrl.split("=")[1];
params = params.replace("data=", '').split('+'); // Array of params
//decode any spaces
params.forEach(function (item, index) {
params[index] = decodeURI(item);
});
//parse the input into variables
if(params[0].equals'_')params[0]=null;
let unit_number = params[0];
let street_number = params[1];
let suburb = params[4];
let street_name = params[2];
// let state_abbreviation = params[4];
let postcode = params[6];
var query = `SELECT TOP 10 * from Adresses
where UNIT_NUMBER ='${unit_number}' AND POSTCODE = '${postcode}' AND SUBURB= '${suburb}'
AND STREET_NAME= '${street_name}' AND STREET_NUMBER = '${street_number}'`;
The problem is not all addresses have unit numbers. I currently deal with this by requriing the unit_number spot in the url to be '_' or a number.
if(params[0].equals'_')params[0]=null;
via Peter jamen
No comments:
Post a Comment