Guest User

Untitled

a guest
Jan 24th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. async function apiController(req, res){
  2. const response = await request.get('http://...........)
  3. res.status(200).json({...})
  4.  
  5. app.get('/myurl', function (req, res) {
  6. makeApiRequest().then(result => {
  7. // We reach here after we are all done with the API.
  8. res.send('here is a response to browser using data from result');
  9. });
  10. });
  11.  
  12. async function makeApiRequest() {
  13. // here, make the API request, do a polling loop, etc.
  14. // eventually return the result
  15. }
  16.  
  17. - Browser client makes JSON request to your server.
  18. - Server makes API call to service, gets back a 'request id'.
  19. - Server sends back request id to browser client.
  20. - Browser client enters loop, every 5 seconds, it sends server a message.
  21. - 'Did my request id complete yet?'
  22. - Server takes request id, asks service 'what is the answer?'
  23. - Send response back to browser.
  24. - Browser client loops until the request is complete, then continues.
Add Comment
Please, Sign In to add comment