import axios from "axios"; import { urlGenerator } from '@Global/services/url.service.js'; export default class axiosApi { constructor(urlObj) { this.staticMethods = ["get", "post", "put", "delete"]; this.baseURL = '/'; this.method = urlObj.method; this.url = urlGenerator(urlObj.url, urlObj.data); console.log(this.url); this.data = urlObj.data; } init() { axios.defaults.baseURL = this.baseURL; if (this.checkMethod()) { return this[this.method](); } } checkMethod() { return this.staticMethods.includes(this.method); } get() { const params = this.data; return axios.get(this.url, { params }); } post() { return axios.post(this.url, this.data); } put() { const data = this.data; data['_method'] = 'put'; return axios.put(this.url, data); } delete() { const data = this.data; data['_method'] = 'delete'; return axios.put(this.url, data); } }