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

gitwithravish's avatar

Eror 404 while making axios request to laravel api in development

I have my api running on localhost:8000 and my vue project running on localhost:8080

I am trying to make axios call to get data from my api but it is always showing 404 error.

How can I troubleshoot this ?

I have already ensured that my laravel server is running properly and the endpoints that I am trying to access exists.

This is my API service

import Vue from "vue";
import axios from "axios";
import VueAxios from "vue-axios";
import JwtService from "@/core/services/jwt.service";

/**
 * Service to call HTTP request via Axios
 */
const ApiService = {
  init() {
    Vue.use(VueAxios, axios);
    Vue.axios.defaults.baseURL = "http://localhost:8000/extranet";
  },

  /**
   * Set the default HTTP request headers
   */
  setHeader() {
    Vue.axios.defaults.headers.common[
      "Authorization"
    ] = `Token ${JwtService.getToken()}`;
  },

  query(resource, params) {
    return Vue.axios.get(resource, params).catch(error => {
      // console.log(error);
      throw new Error(`[KT] ApiService ${error}`);
    });
  },

  /**
   * Send the GET HTTP request
   * @param resource
   * @param slug
   * @returns {*}
   */
  get(resource, slug = "") {
    return Vue.axios.get(`${resource}/${slug}`).catch(error => {
      // console.log(error);
      throw new Error(`[KT] ApiService ${error}`);
    });
  },

  /**
   * Set the POST HTTP request
   * @param resource
   * @param params
   * @returns {*}
   */
  post(resource, params) {
    return Vue.axios.post(`${resource}`, params);
  },

  /**
   * Send the UPDATE HTTP request
   * @param resource
   * @param slug
   * @param params
   * @returns {IDBRequest<IDBValidKey> | Promise<void>}
   */
  update(resource, slug, params) {
    return Vue.axios.put(`${resource}/${slug}`, params);
  },

  /**
   * Send the PUT HTTP request
   * @param resource
   * @param params
   * @returns {IDBRequest<IDBValidKey> | Promise<void>}
   */
  put(resource, params) {
    return Vue.axios.put(`${resource}`, params);
  },

  /**
   * Send the DELETE HTTP request
   * @param resource
   * @returns {*}
   */
  delete(resource) {
    return Vue.axios.delete(resource).catch(error => {
      // console.log(error);
      throw new Error(`[RWV] ApiService ${error}`);
    });
  }
};

export default ApiService;

0 likes
4 replies
automica's avatar

I would recommend downloading postman and setting up a request to match what your axios call is doing.

This will determine if your fault is with your Vue component or with your backend.

If you are getting a 404 it could be you are hitting an earlier route in your routes list. It’s worth using laravel routes/api.php to avoid collisions that way.

Also check php artisan route:list to see if the route you aren’t able to access is showing up.

bshbair's avatar
bshbair
Best Answer
Level 1

If you are using Metronic Vue, go to "src/main.js" and remove the following line

MockService.init();

gitwithravish's avatar

Kinda stupid mistake i know... Thanks for pointing it out

neilstee's avatar

@gitwithravish

I have already ensured that my laravel server is running properly and the endpoints that I am trying to access exists.

When you say it exists, you mean you have tested it?

Please or to participate in this conversation.