Level 51
Yes, use axios instance.
The header you define while creating that instance will be sent to all requests using that instance.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi,
II am building an app with a Laravel backend api and a vue.js front end.
Part of the application is password protected, so I am making requests with headers to authenticate, for example:
await axios
.get(`/api/products/${param.productId}`, {
headers: {
Authorization: `Bearer ${userStore.user.token}`,
token: userStore.user.token
}
})
.then((response) => {
localState.product = response.data.data
});
Is there a way to add headers to all requests in the password protected area to tidy this up?
Please or to participate in this conversation.