const SUCCESS_CODE = 200;
export async function httpGet(url) {
    let err = null;
    let getData = null;
    try {
        const response = await fetch(url);
        if (response.status != SUCCESS_CODE) {
            err = `HTTP get error for ${url}: ${response.status} ${response.statusText}`;
        }
        else {
            getData = await response.json();
        }
    }
    catch (error) {
        err = error;
    }
    return { err, getData };
}
export async function httpPost(url, jsonData) {
    let err = null;
    try {
        const response = await fetch(url, {
            method: "POST",
            body: JSON.stringify(jsonData),
            headers: { "Content-type": "application/json; charset=UTF-8" },
        });
        if (response.status != SUCCESS_CODE) {
            err = `HTTP post error for ${url}: ${response.status} ${response.statusText}`;
        }
    }
    catch (error) {
        err = error;
    }
    return { err };
}
export async function httpPut(url, jsonData) {
    let err = null;
    try {
        const response = await fetch(url, {
            method: "PUT",
            body: JSON.stringify(jsonData),
            headers: { "Content-type": "application/json; charset=UTF-8" },
        });
        if (response.status != SUCCESS_CODE) {
            err = `HTTP put error for ${url}: ${response.status} ${response.statusText}`;
        }
    }
    catch (error) {
        err = error;
    }
    return { err };
}
export async function httpPatch(url, jsonData) {
    let err = null;
    try {
        const response = await fetch(url, {
            method: "PATCH",
            body: JSON.stringify(jsonData),
            headers: { "Content-type": "application/json; charset=UTF-8" },
        });
        if (response.status != SUCCESS_CODE) {
            err = `HTTP patch error for ${url}: ${response.status} ${response.statusText}`;
        }
    }
    catch (error) {
        err = error;
    }
    return { err };
}
export async function httpDelete(url) {
    let err = null;
    try {
        const response = await fetch(url, {
            method: "DELETE",
        });
        if (response.status != SUCCESS_CODE) {
            err = `HTTP delete error for ${url}: ${response.status} ${response.statusText}`;
        }
    }
    catch (error) {
        err = error;
    }
    return { err };
}
//# sourceMappingURL=REST.js.map