jet
1 week ago
112
1
Vue

how can i create a service that will be responsible for all my api an consume it with the component

Posted 1 week ago by jet

here is what i try doing postService


import axios from "axios";

const baseDomain = "/academic/";
const baseURL = `${baseDomain}/`;

const Repository = axios.create({
  baseURL,
  // headers: { Authorization: `Bearer yourSuppaToken` }
});

const resource = "/academicsession";

export default {
  // Just FYI...

  getAll() {

   return Repository.get(`${resource}`);
 },
  getOne() {

   return Repository.get(`${resource}`);
   // return Repository.get(`${resource}/${postId}`);

 },
  createOne(payload) {

   return Repository.post(`${resource}`, payload);
 },
  updateOne(id, payload) {

   return Repository.put(`${resource}`,id, payload);
 },
  deleteOne(id) {

   return Repository.post(`${resource}`, id);
 },

};

how can i use it in the component

Please sign in or create an account to participate in this conversation.