Accessing headers when using $fetch
Is it possible to access the raw response to get the headers using $fetch?
$fetch in Nuxt. You can do this by using the method. Here's how you can access the headers:Nuxt includes the ofetch library, and is auto-imported as thealias globally across your application.$fetch
$fetch is based on, provides this capability to access the raw response.useRequestFetch composable, which automatically forwards request headers in server-side fetch requests.$fetch or useFetch in Nuxt, I'll need to provide some clarification and context based on the available information in the knowledge sources.$fetch or useFetch in Nuxt. This option is not a standard feature of Nuxt's built-in fetch utilities as described in the documentation.useFetch and $fetch are based on the library, which might have additional options not explicitly covered in the Nuxt documentation. If you're using a custom function, it would typically be used to transform the response before it's returned.useFetch in Nuxt, you would typically access the data like this:data would contain the result of that parsing function.$fetch and useFetch in Nuxt, we can infer the following:$fetch is based on .$fetch.raw$fetch.raw$fetch.raw$fetch.raw$fetch.raw$fetch.raw$fetch.rawres._dataparseResponseparseResponseparseResponseparseResponseparseResponseparseResponseparseResponseparseResponseparseResponseofetchofetchofetchofetch$fetch.raw('...', parseResponse: (value) => ({ foo: 'bar' }))_data_dataconst res = await $fetch.raw('/api/endpoint')
const headers = res.headersconst { data } = await useFetch('/api/endpoint')
console.log(data.value)const res = await $fetch.raw(url)
return res._dataconst res = await $fetch.raw('...', {
parseResponse: (value) => ({ foo: 'bar' })
})
const parsedData = res._data
console.log(parsedData) // Should output { foo: 'bar' }