JavaScript API

BY Guanqiao Huang

Posted by HUANG on January 3, 0201

Postman

Postman Download

API Example

JokeAPI

 async function getJoke() {
   /*
   //只是看他创建成功与否, status 200代表成功
    fetch("https://v2.jokeapi.dev/joke/Programming")
      .then((d) => {
        console.log(d);
      })
      .catch((e) => {
        console.log(e);
      });
      */
   let data = await fetch("https://v2.jokeapi.dev/joke/Programming");
   let parsedData = await data.json();
   console.log(parsedData);
 }

 getJoke();

OpenWeather

let myKey = "94ac710d45e940969debbd3923119224";
//let city = "Canberra";
let city = prompt("Enter a city name:");
let url = `https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${myKey}`;

async function getWeather(){
let data = await fetch(url);
let dataJson = await data.json();
console.log(dataJson);
}

getWeather();