Skip to content

Instantly share code, notes, and snippets.

@overthemike
Created December 6, 2017 23:29
Show Gist options
  • Save overthemike/e527561be093824f1c533a664e42f3c8 to your computer and use it in GitHub Desktop.
Save overthemike/e527561be093824f1c533a664e42f3c8 to your computer and use it in GitHub Desktop.
// THIS IS OUR SERVER CODE SNIPPET
// this is the api call on our express server
// it's job is to take a call from our frontend
// and call another api when it's called and return
// that data back to the frontend
router.get('/mycall', function(req,res,nex){
request.get('http://someotherdomain.com/api/a/call/to/make', function(error, response, body){
// notice the difference between res and response
// now we respond back to our frontend with the
// data from the other domain's api
res.json(body) // send the data back to the frontend
})
})
// THIS IS OUR FRONTEND CODE SNIPPET
axios.get('/mycall').then(function(resp){
// now we have the api data we need to do stuff with
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment