Friday, 8 February 2019

I am confused on exactly how to pass a token received from server to a specific api route

Right now this is how I am doing it.1) I have an ajax call on client side which hits a route like "/gettoken"2) When the above is called, its passed to my node server where I do a router.get("/gettoken", function etc etc), and within this, I do a router.post("url of external server i want to get token from", function etc etc), then res.json(response.token).3) Then on client side in the call i made in 1) I get the response inside the .then(function(data)), i use that token received on client side to send another ajax call (yes an ajax call within an ajax call). The 2nd ajax call sends the toke to another route like "/sendtokenforapicall"4) on node server side again, I use router.get("/sendtokenforapicall") and within this I do a router.post("url for external api route") and pass the token along with it to get the relevant response back​Is my flow correct? what is the correct way or better way of doing this?

Submitted February 08, 2019 at 09:18PM by gqtrees

No comments:

Post a Comment