Syncing two apis

Hi, How do you sync two apis? Let say I have to fetch data from one api, then display it to another api… I would be the middle api… I am not sure how to do this. Can anyone recommend a tutorial, tools, or maybe an example? I can usally reverse engineer things I see, but I just need some type of examples.
Thanks!

I’m not sure what you mean by “then display it to another api”.

Taking your question more generally, if you have one asynchronous action that depends on the result of another asynchronous action, then you need to chain them together. Once way is with nested callbacks. This is a simpler way, but it gets messy. Using Promises is a step up. So is async/await (basically syntactic sugar to make the asynchronous aspects of Promises look synchronous). There are also generator functions, but that’s getting pretty advanced.

I am looking for examples, or tutorials. Basically, I need to fetch data from an api, then post that data to another application, but the scripts to do it needs to be written outside the application.
Data API <-----> My Script API<------> Application API
I am not sure how to do this or what tools to use…
I have fetched data multiply times from data bases and mapped them into a frontend application, writing a script within the application itself… So I am thinking writing a script outside the application to fetch data and send ii to the other application…
I am not sure how to achieve this or where to start… and examples or tutorials would be greatly appreciated.

I don’t understand “but the scripts to do it needs to be written outside the application”.

Are you saying you want one endpoint for your client to hit? Then you’d need to wrap these in a microservice, but within that microservice, you’ll run into the same asynchronous issues.

Here is a SO question dealing with chained fetches. This is an article discussing it. I’m sure if you google “chain javascript fetch” you’ll find a bunch of examples.

If that’s your business logic, why not simply implement it?
From the way you describe it seems you know how to GET and POST data.
At the core that’s all you have to do: GET data first, then POST it.

What’s confusing you about this?
If it’s just the matter of “where” do it, you can do this in so many possible way.

  • a simple script that programmatically do that.
  • a small CLI to solve this.
  • spin a server with endpoint to perform the above.
    [… and many more]

The above depends all on what technology you are familiar and comfortable working with.

But in theory you can do that all in a terminal using cURL to GET and POST requests. :slight_smile:

1 Like

Thank you! I was actually looking into this now and this is what I found upon my research! I only wish I had it days earlier. Exactly , what you have written above is what I am in the process of doing… thanks so much!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.