Created
March 18, 2021 19:35
-
-
Save HenriqueMitsuo/284f424c1b53467d81e86967233b9f36 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// import axios from "axios"; | |
import { axios } from "@/plugins/axios"; // vue | |
export class ApiService { | |
constructor(Resource) { | |
this.Resource = Resource; | |
this.Token = { Authorization: `Bearer ${localStorage.getItem("token")}` }; | |
} | |
async queryAll() { | |
try { | |
const response = await axios.get(this.Resource, { headers: this.Token }); | |
return await response.data; | |
} catch (error) { | |
console.log(`Server error: ${error}`) | |
} | |
} | |
async queryOne(id) { | |
const response = await axios.get(`${this.Resource}/${id}`, { headers: this.Token }); | |
return await response.data; | |
} | |
async queryFilter(filter) { | |
const response = await axios.get(this.Resource, { headers: this.Token, params: filter }); | |
return await response.data; | |
} | |
async createOne(data) { | |
const response = await axios.post(this.Resource, data, { headers: this.Token }); | |
return await response.data; | |
} | |
async updateOne(id, data) { | |
const response = await axios.put(`${this.Resource}/${id}`, data, { headers: this.Token }); | |
return await response.data; | |
} | |
async deleteOne(id) { | |
const response = await axios.delete(`${this.Resource}/${id}`, { headers: this.Token }); | |
return await response.data; | |
} | |
// Controle de usuário (Auth de login, Criação) | |
async login(data) { | |
const response = await axios.post(this.Resource, data); | |
return await response.data; | |
} | |
async createUser(data) { | |
const response = await axios.post("register", data); | |
return await response.data; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment