Skip to content

Instantly share code, notes, and snippets.

@gentilmente
Created August 9, 2021 01:01
Show Gist options
  • Save gentilmente/67ab5df0767c486573e7856b8df212ca to your computer and use it in GitHub Desktop.
Save gentilmente/67ab5df0767c486573e7856b8df212ca to your computer and use it in GitHub Desktop.
manage two public APIs
//https://apipheny.io/free-api/
const fetch = require("node-fetch");
const text = fetch("https://catfact.ninja/fact")
.then((res) => res.json())
.then((json) => {
const text = json.fact;
console.log(text + "\n");
fetch("https://libretranslate.de/translate", {
method: "POST",
body: JSON.stringify({
q: text,
source: "en",
target: "es",
}),
headers: { "Content-Type": "application/json" },
})
.then((res) => res.json())
.then((json) => console.log(json.translatedText));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment