axiosservice.js
unknown
javascript
a year ago
922 B
4
Indexable
Never
import axios from 'axios' import ToastService from "../toast/ToastService" import {useToastStore} from "../../stores/toast-store"; const toast = new ToastService(); export default class AxiosService { httpRequest(method, url, request) { return axios[method](url, request) .then(response => { if (method !== 'get') { toast.success(response) } }) .catch(error => toast.error(error)) } get(url, request) { return this.httpRequest('get', url, request) } delete(url, request) { return this.httpRequest('delete', url, request) } post(url, request) { return this.httpRequest('post', url, request) } put(url, request) { return this.httpRequest('put', url, request) } patch(url, request) { return this.httpRequest('patch', url, request) } }