import instance from "./axios"

const post = (url, data,header='application/x-www-form-urlencoded') => {
    return new Promise((resolve, reject) => {
        instance.post(url, data,{
            headers: {
                "Content-Type": header,
            },
        }).then(res => {
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
}
const get = (url, data={}) => {
    return new Promise((resolve, reject) => {
        instance.get(url, { params: data }).then(res => {
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
}
const put = (url, data,header='application/x-www-form-urlencoded') => {
    return new Promise((resolve, reject) => {
        instance.put(url, data,{
            headers: {
                "Content-Type": header,
            },
        }).then(res => {
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
}

const del = (url, data,header='application/x-www-form-urlencoded') => {
    return new Promise((resolve, reject) => {
        instance.delete(url,data, {headers: {
            "Content-Type": header,
        }}).then(res => {
            resolve(res)
        }).catch(err => {
            reject(err)
        })
    })
}

export default {
    post, get, put, del
}