export const server = {
    postUrl: async (url: string | URL | Request, data: any) => {
        try {
            return await fetch(url, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json; charset=UTF-8',
                },
                body: data,
            }).then(async (res) => {
                return res.json().then(async (r) => {
                    return r
                })
            })
        } catch (e) {
            console.log(e)
        }
    },

    postUrlKey: async (url: string | URL | Request, data: any) => {
        try {
            return await fetch(url, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json; charset=UTF-8',
                    'idempotency-key': `b5f8c7db82644de2d`,
                    Authorization: `Bearer sk_test_ec2062606b84ef7aaf2fca4f62247a27348cca1656740988`,
                    // Authorization: `Bearer sk_test_ec2062606b84ef7aaf2fca4f62247a27348cca1656740988`,
                },
                body: data,
            }).then(async (res) => {
                return res.json().then(async (r) => {
                    return r
                })
            })
        } catch (e) {
            console.log(e)
        }
    },

    putUrl: async (url: string | URL | Request, data: any) => {
        try {
            return await fetch(url, {
                method: 'PUT',
                headers: {
                    'Content-Type': 'application/json; charset=UTF-8',
                },
                body: data,
            }).then(async (res) => {
                return res.json().then(async (r) => {
                    return r
                })
            })
        } catch (e) {
            console.log(e)
        }
    },

    getUrl: async (url: string | URL | Request) => {
        return await fetch(url, {
            method: 'GET',
            headers: {
                'Content-Type': 'application/json; charset=UTF-8',
            },
        }).then(async (res) => {
            return res.json().then(async (r) => {
                return r
            })
        })
    },

    deleteUrl: async (url: string | URL | Request) => {
        try {
            return await fetch(url, {
                method: 'DELETE',
                headers: {
                    'Content-Type': 'application/json; charset=UTF-8',
                },
            }).then(async (res) => {
                return res.json().then(async (r) => {
                    return r
                })
            })
        } catch (e) {
            console.log(e)
        }
    },
}
