const api_endpoint = "http://localhost:8000";

const fetchFromEndpoint = async (endpoint, token) => {
    return await fetch(`${api_endpoint}${endpoint}`, { headers: { Authorization: `Token ${token}` } });
}

const getToken = async (username, password) => {
    const body = new FormData();
    body.append("username", username);
    body.append("password", password);

    const response = await fetch(`${api_endpoint}/get-token/`, {
        method: "POST",
        body: body,
    });

    const status = response.status;
    const data = await response.json();
    const statusMessage = response.statusText;

    return { status, statusMessage, data };
};

export { fetchFromEndpoint, getToken };