surfmuggle / Cubert

To become a jedi one must start as a novice
BSD 3-Clause "New" or "Revised" License
2 stars 0 forks source link

JavaScript - learn about and use fetch #30

Open surfmuggle opened 3 years ago

surfmuggle commented 3 years ago

fetch is a function to make HTTP requests

surfmuggle commented 3 years ago
  1. Calling fetch returns a promise that resolves to a Response object
  2. To get at the actual content of a response, you can use its text method.
  3. the initial promise is resolved as soon as the response’s headers have been received
  4. the response body might take a while longer, this again returns a promise
fetch("example/data.txt")
  .then(resp => resp.text())
  .then(text => console.log(text));
// → This is the content of data.txt