Closed tacxou closed 1 year ago
Indeed, global headers can be overridden by any composable. This is intentional and not a bug, since for a specific request you may want to adapt a certain header, which you have already declared in the apiParty
module options. This allows users to have full control without being bound to global defaults in every call.
useApiData(path, {
headers: {
// Will overriden the global `foo` header if present
foo: 'baz'
}
})
In fact, I want to act globally. Except that I can't type the composable so that it retains OpenAPI autocompletion. I think an example of this very common authentication case would be necessary.
I see. Please take a look into the module configuration docs. You can define global headers per API endpoint:
export default defineNuxtConfig({
apiParty: {
endpoints: {
myApi: {
url: process.env.MY_API_BASE_URL!,
// Define global headers here. They will be used with every `$myApi` or `useMyApiData` call.
headers: {
Authorization: `Bearer ${process.env.MY_API_TOKEN}`
}
},
}
}
})
What if I want to take my header from a blind in this case? Doesn't your approach work?
Describe the feature
Example ?
Additional information
Final checks