const request = async (href, data, method,headers) => {
    try {
        const options = {
            method,
            headers,
        }
        if (data !== null) {
            options.body = data
        }
        const {host, origin} = window.location
        const api = host === "localhost" ? `${origin}/demirteknoloji/${href}` : `${origin}/${href}`
        const response = await fetch(api, options)
        return response.json()
    } catch (e) {
        return e
    }
}

export const post = async (href, data) => await request(href, data, "POST",{
    "Accept": 'application/json, text/plain, */*',
})
export const postJson = async (href, data) => await request(href, JSON.stringify(data,null,2), "POST",{
    "Content-Type": "application/json",
    "Accept": 'application/json, text/plain, */*',
})

export const _get = async (href) => await request(href, null, "GET",{
    "Content-Type": "application/json",
    "Accept": 'application/json, text/plain, */*',
})


export const customFetch = async (href,data,method,headers) => await request(href, data, method,headers)