#How to call external API? Directly, or via server api?

2 messages · Page 1 of 1 (latest)

outer magnet
#

Hi,
I'm writing a Nuxt 3 application for a frontend and as a backend I'm connecting to an external api.

Should I $fetch to external API directly from the component, or is it important to call Nuxt server/api first and within this server/api make external api (because of SSR)?

Thanks

sweet lantern
#

You don't have to use the /api folder to make call to an external API if you don't want to do anything specific with the data on your server or if you don't have any logic on your backend.

The way something like useAsyncData works is that the data returned from the async call is available both on your server during the SSR process and your client in the regular SPA lifecycle (assuming you're using SSR as a rendering mode)