georgiev955

demo with firebase

Oct 26th, 2023 (edited)
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fetch("https://fir-6e9c1-default-rtdb.europe-west1.firebasedatabase.app/Books.json")
  2.     .then((res) => {
  3.         return res.json();
  4.     })
  5.     .then((response) => {
  6.         for (const key in response) {
  7.             console.log(response[key]);
  8.         }
  9.     })
  10.     .catch(err => {
  11.         console.error(err);
  12.     })
  13.  
  14.  
  15. fetch("https://fir-6e9c1-default-rtdb.europe-west1.firebasedatabase.app/Books.json", {
  16.     method: "PUT",
  17.     headers: {
  18.         "Content-Type": "application/json"
  19.     },
  20.     body: JSON.stringify({
  21.         Author: 'John Doe',
  22.         'Books Genre': 'Scifi',
  23.         Title: 'Demo book'
  24.     })
  25. })
  26.     .then((res) => {
  27.         if (res.ok) {
  28.             console.log("PUT request was successful.");
  29.         } else {
  30.             console.error("PUT request failed.");
  31.         }
  32.     })
  33.     .catch(err => {
  34.         console.error(err);
  35.     });
Advertisement
Add Comment
Please, Sign In to add comment