DEV Community

sium_hossain
sium_hossain

Posted on • Edited on

1 1

How to send multiple requests parallelly in fetch hook - Nuxt

Let's declare a method to fetch data from multiple endpoint.

methods:{
// rest of your methods 
async fetchData(){
     let [res1, res2, res3] = await Promise.all(
         this.$axios.$get('api/endpoint/1'),
         this.$axios.$get('api/endpoint/2'),
         this.$axios.$get('api/endpoint/3'),
         )
     // check your response and whatever you want with those response
     console.log(res1)
     console.log(res2)
     console.log(res3)
}
Enter fullscreen mode Exit fullscreen mode

Then you can call this method in fetch hook -

async fetch(){
      await this.fetchData()
}
Enter fullscreen mode Exit fullscreen mode

Thank you

😎 Read more -

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (1)

Collapse
 
agentprivatbanka profile image
agent_privatbanka

Promise.all([...])

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more