<reponame>HansUrpay/Proyecto_DRF_API_v2<filename>front/rest_js/list.js<gh_stars>0const html_botones = document.querySelector("#botones");
const html_list = document.querySelector("#html_list");

const url = "http://127.0.0.1:8000/api2/";

async function getAPI() {
  try {
    const options = {
      method: "GET",
      headers: {
        "Content-Type": "application/json",
        'Authorization': 'Bearer ' + 'ax5kh6jaqkcd2tiexxs8v6xjo8yv8a6bGApOXkngqEW1-5Fj4EW_4GIoQIPAmPYAqh4Qlq3sEBQ'
      }
    };
console.log(options)
    const response = await fetch(url, options);
    const data = await response.json();
    data.forEach((value) => {
      html_list.innerHTML += listar_data(value);
    });
  } catch (error) {
    console.log(error);
  }
}

function listar_data(value) {
  return `
  <li>Nombre: <strong>${value.nombre}</strong></li>
  <li>Prioridad: ${value.prioridad}</li>
  <li>Creacion: ${value.created_at}</li>
  <a href="/rest_html/detail.html?hola=1&id=${value.id}">Detalles</a>
  <a href="/rest_html/delete.html?hola=1&id=${value.id}">Delete</a>
  <a href="/rest_html/update.html?hola=1&id=${value.id}">Update</a>
  <hr></hr>
  `;
}

getAPI();
