import Vue from "vue"; import axios from "axios"; import VueAxios from "vue-axios"; const ApiService = { init() { Vue.use(VueAxios, axios); Vue.axios.defaults.baseURL = process.env.VUE_APP_SERVICE_API; }, query(resource, params) { return Vue.axios.get(resource, params).catch((error) => { throw new Error(`ApiService ${error}`); }); }, get(resource, slug = "") { let url = resource if (slug !== "") url = url + `/${slug}` return Vue.axios.get(url).catch((error) => { throw new Error(`ApiService ${error}`); }); }, post(resource, params) { return Vue.axios.post(`${resource}`, params); }, update(resource, slug, params) { return Vue.axios.put(`${resource}/${slug}`, params); }, put(resource, params) { return Vue.axios.put(`${resource}`, params); }, delete(resource) { return Vue.axios.delete(resource).catch((error) => { throw new Error(`ApiService ${error}`); }); }, }; export default ApiService;
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter