Llamar a una API es una de las tareas más comunes en programación.
Implementa una llamada HTTP a una API (la que tú quieras) y muestra su resultado a través de la terminal. Por ejemplo: Pokémon, Marvel...
Aquí tienes un listado de posibles APIs: https://github.com/public-apis/public-apis
const fetch = require("node-fetch");
const URL_API = 'https://swapi.dev/api/people/1/';
const getLuke = async () => {
const response = await fetch(URL_API);
const data = await response.json();
return data;
};- First, I import the fetch module from node-fetch to make the HTTP request.
const fetch = require("node-fetch");- Then, I define the URL of the API in this case the Star Wars API.
const URL_API = 'https://swapi.dev/api/people/1/';- I create an async function to make the request and return the data.
const getLuke = async () => {
...
}- I use the await keyword to wait for the response and then I convert it to JSON.
const getLuke = async () => {
const response = await fetch(URL_API);
const data = await response.json();
return data;
};