Tuesday 23 October 2018

Node newb question regarding the traditional callback approach with http clients

I've been programming for years but only recently with node.js. I'm happily async/await where I can and I've recently been working on a project which requires an http client.I've been wondering about this, with Python, for example it's extremely easy to write http clients using the Requests module and I've written a lot of code which does this:Request an http resource (GET, POST, whatever).Block and receive the response.Store the response (or part of it) in a variable.Do stuff the the response data.However, I can't wrap my head around doing that above with callbacks. How could I effectively issue an http request, wait for the response and then proceed?How do I the same with Promises? The way that Node does async feels a bit foreign to me at this point. I know I'm missing something obvious. See my other post for an example of me doing the above with async/await - how could that code be rewritten with callbacks or Promises?https://ift.tt/2CANZw3 in advance!

Submitted October 23, 2018 at 03:53PM by tech_tuna

No comments:

Post a Comment