Monday, 18 November 2019

Beginner question regarding APIs and Dynamic Rendering

I’m trying to learn express and node by building a side project. I’ve been doing some udemy courses to learn but I’m stumped on this one. I want to render the content of a page by making a fetch call to the amiibo api (since it’s free and no key). I want to change the api call based on the url. I’ve been trying a bunch of things to no success. What would be the best way to attempt to render the page using the results of the api call and the req.params? I’m creating the elements based on the size of the array that returns. Sorry if this is not right place to ask this but I’ve spent countless hours and I’m not really any closer to figuring this out.Here's how I make the API call import { elements } from "./elements";async function displayAmiibo() { const amiiboTitle = document.getElementsByClassName("header-title").value; console.log(amiiboTitle); const amiiboUrl = https://www.amiiboapi.com/api/amiibo/?gameseries=${amiiboTitle};try { const result = await fetch(amiiboUrl); const data = await result.json(); data.amiibo.forEach(element => { elements.displayArea.insertAdjacentHTML( "beforeend",
  • Name:${element.character}
  • Series:${element.amiiboSeries}
); }); } catch (error) { console.log(error); }displayAmiibo();

Submitted November 19, 2019 at 02:01AM by mike3640

No comments:

Post a Comment