Created
December 6, 2017 23:29
-
-
Save overthemike/e527561be093824f1c533a664e42f3c8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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