2024-03-05 11:36:21 +03:00

40 lines
888 B
JavaScript

import axios from "axios";
const post = async (path, data, onError) => {
return await axios.post(path, data)
.then(r => r.data)
.catch(error => {
onError && onError(error)
console.error('Error post request:', error)
})
}
const get = async (path) => {
return await axios.get(path)
.catch(error => {
console.error('Error get request:', error)
})
}
const put = async (path, data, id, onError) => {
return await axios.put(`${path}/${id}`, data)
.then(r => r.data)
.catch(error => {
onError && onError(error)
console.error('Error put request:', error)
})
}
const remove = async (path, id, onError) => {
return await axios.delete(`${path}/${id}`)
.then(r => r.data)
.catch(error => {
onError && onError(error)
console.error('Error delete request:', error)
})
}
export {get, post, put, remove}