Home > Back-end >  Use data from one api call in another api call concurrently
Use data from one api call in another api call concurrently

Time:11-09

How to use data as a result from api call as a response in another concurrently?

I've got this function

const foo = async() => {
  await firstCall()
  await secondCall()
}

calling firstCall() i want to get data and save them inside some variable and when this data is received use data as params inside secondCall()

CodePudding user response:

Declare a variable data inside your async function foo and assign it a value which is the value returned from calling the firstCall function:

  const foo = async() => {
   const data = await firstCall()
   await secondCall(data)
}

For more info you can read documentations at MDN - async function.

  • Related