/**
 * @file AxiosService.js
 * @author Radim Buráň (xburan03@stud.fit.vutbr.cz)
 */

import axios from "axios";

const instance = axios.create({
    withCredentials: true,
    baseURL: process.env.REACT_APP_SERVER_URL
})

async function axiosPost(path, data, props = {}) {
    return await instance.post(path, data, props);
}

async function axiosGet(path, params = {}) {
    return await instance.get(path, { params : params});
}

async function axiosPatch(path, data, props = {}) {
    return await instance.patch(path, data, props);
}

async function axiosRemove(path, data = {}) {
    return await instance.delete(path, data);
}

function axiosSetAuthToken(token) {
    instance.defaults.headers["authorization"] = token ? ("Bearer " + token) : "";
}


export {
    axiosPost, axiosGet, axiosPatch, axiosRemove, axiosSetAuthToken
}


