Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mvind's avatar
Level 1

Setup localhost Api development for consuming own API

Hi everyone!

I have setup my website so I can consume my own api, after 8 hours of swearing and banging my head agaisnt my wall this finally works. So I can make axios calls inside my vue component.

Now I prefer to develop api In a local envoirment using php artisan serve. But when I try to consume my Api from this local site I get the following error:

Failed to load resource: the server responded with a status of 401 ()
app.js:2 Uncaught (in promise) Error: Request failed with status code 401

I have already added cors handling. But let me repeat this works fine for my production website.

Does anyone have any clues for getting this working?

Hope my question make sense - else please ask

Thanks for reading,

/mvind

0 likes
1 reply
mvind's avatar
mvind
OP
Best Answer
Level 1

Okay so I figured it out. The problem was quite simple. You can simply add to your bootstrap.js

window.axios.defaults.baseURL = 'http://localhost:3000/' // development 
// window.axios.default.baseURL = 'https://yourwebsite.com/' // prod

And remember to switch to the correct baseURL when you push to production.

Please or to participate in this conversation.