export default {
    async f(url, method, token = null, data = null, json = false) {
        const API = 'http://yarik.protasevich.fun/api/';

        let options = {
            method: method.toUpperCase(),
            mode: 'cors',
            headers: {
                'Authorization': `Bearer ${token}`
            }
        };

        if (json) options.headers["Content-Type"] = "application/json";

        if (
            method === "POST" ||
            method === "PATCH"
        ) {
            options.body = data;
        }

        let response = await fetch(`${API}${url}`, options);

        return {
            body: await response.json(),
            code: response.status
        };
    }
}