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

fahaddsheikh's avatar

Axios post request returns 404 on all apis

Hello,

this has been extremely annoying, regardless of whichever api I request, a public one on the internet which works everywhere else (I tested) or a localhost api I created on laravel 7.1 (it works on postman), i get the same error of Error: Request failed with status code 404 .

When i looked for this on the internet, i saw two possible problems, either I am using the wrong URL which I checked is correct or this could be a cors problem which I also checked and comes out of the box with laravel 7.1. Even if it wasnt working with my laravel local install the API request should atleast work for other public apis im using just to test, they also fail.

I am using a premium theme by material UI.

Axios Code

loginWithEmailAndPassword = (email, password) => new Promise((resolve, reject) => {
    var url = process.env.REACT_APP_API_URL + 'api/seller/login';
    axios.post(url, { email, password })
      .then((response) => {
        if (response.data.user) {
          this.setSession(response.data.accessToken);
          resolve(response.data.user);
        } else {
          reject(response.data.error);
        }
      })
      .catch((error) => {
        console.log(url);
        console.log(error);
        reject(error);
      });
  })

0 likes
4 replies
fahaddsheikh's avatar

I was able to get to the bottom of this problem. I was including axios as import axios from 'src/utils/axios';

which had the following code:

import axios from 'axios';

const instance = axios.create();

export default instance;

so when i changed import axios from 'src/utils/axios'; to import axios from 'axios'; it worked!

What I still don't get is why it didn't work with the previous file? I looked into instances and saw we could define a baseURL which I did and change the code in src/utilis/axios to

import axios from 'axios';

const instance = axios.create({baseURL: process.env.REACT_APP_API_URL});

export default instance;

but it still doesnt work. Could someone please give me an insight on instances and why the above doesnt work

Tray2's avatar

Use the developer tools in your browser and check what uri it's giving the 404 on. It's most likely not pointing to the same uri as your postman request.

fahaddsheikh's avatar

I don't get an XHR request in the network tab for this error. I only get the request in network tab when I use import axios from 'axios'

1 like
stevegb's avatar

Probably solved by now, but ran into this same problem. Was also building from a theme and the singleton of the axios instance was being imported and modified in another file. Specifically, axios endpoints were being mocked using axios-mock-adapter, which explains why no requests were ever sent across the network.

Please or to participate in this conversation.