2

I have been using the asynchronous abilities of Node.js from quite some time now. But I am stuck on an interesting problem. Basically I have 2 API's that I need to call one after the other. Due to the asynchronous nature of Node.js I cannot retrieve the response of the first API request till it has finished and the respective callback function is called. What I want to do is that I want to pass the response from the first API as request payload to the second API on the fly and not wait till the first API gets fully completed.

As a possible alternative, should I switch from building rest API to stream APIs?

Any pointers on how to do this?

Thanks

4
  • Probably you'll need to convert your first API to stream API (not REST) and then process the stream as it gets sent to the client. You might not be using Twitter's API but they have a great explanation of the difference between those two. Check it out here Commented Sep 13, 2015 at 7:24
  • @NoobCoder Thanks for the comment! Both the API'S that am talking about our my own custom API's .. how do I create a stream API out of a REST API? Commented Sep 15, 2015 at 19:23
  • So you're building a streaming proxy? Commented Sep 19, 2015 at 17:51
  • @MattHarrison I couldn't get your question. Could you elaborate? Commented Sep 19, 2015 at 17:52

1 Answer 1

1

Yes, converting REST API'S to stream API is a better option. Node.js is known for its asynchronous behaviour. Because of the same all REST api's function in the same manner as you described earlier. As someone has previously pointed you could look at the Twitter Stream API for reference.

For more understanding you can check out this link - How to create a streaming API with NodeJS

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.