Skip to content

Instantly share code, notes, and snippets.

@w3cj
Created June 11, 2018 15:13
Show Gist options
  • Save w3cj/7b07fde8803af6857f6a3e725d8b01af to your computer and use it in GitHub Desktop.
Save w3cj/7b07fde8803af6857f6a3e725d8b01af to your computer and use it in GitHub Desktop.
app.get('/search/:location/:job', (request, response) => {
const { location, job } = request.params;
const cl = `https://${location}.craigslist.org/search/jjj?query=${job}`;
const reddit = `https://www.reddit.com/r/jobbit/search.json?q=${job}&restrict_sr=1`;
Promise.all([
fetch(cl)
.then(response => response.text()),
fetch(reddit)
.then(res => res.json())
]).then(results => { // results is an array with the results of both fetch calls
const body = results[0];
const clJson = craigslistGet(body);
const redditJson = results[1];
response.json({
redditJson,
clJson
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment