Nuxt uses ofetch to expose globally theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/nuxt/nuxt/llms.txt
Use this file to discover all available pages before exploring further.
$fetch helper for making HTTP requests within your Vue app or API routes.
During server-side rendering, calling
$fetch to fetch your internal API routes will directly call the relevant function (emulating the request), saving an additional API call.Usage
We recommend usinguseFetch or useAsyncData + $fetch to prevent double data fetching when fetching the component data.
$fetch in any methods that are executed only on client-side.
If you use
$fetch to call an (external) HTTPS URL with a self-signed certificate in development, you will need to set NODE_TLS_REJECT_UNAUTHORIZED=0 in your environment.Passing Headers and Cookies
When we call$fetch in the browser, user headers like cookie will be directly sent to the API.
However, during Server-Side Rendering, due to security risks such as Server-Side Request Forgery (SSRF) or Authentication Misuse, the $fetch wouldn’t include the user’s browser cookies, nor pass on cookies from the fetch response.
useFetch with a relative URL on the server, Nuxt will use useRequestFetch to proxy headers and cookies (with the exception of headers not meant to be forwarded, like host).