Notes on Day 6 of 30 Days of JavaScript

There are many ways to access data from APIs and fetch is a common starting point in learning dynamic data. I remember my Internet Programming class in 2012 and this was our introduction to the world of AJAX.

Table of Contents

Lessons Learned

fetch()

This method “starts the process of fetching a resource from the network, returning a promise which is fulfilled once the response is available” and it returns a Response object containing the data from the source point.

Note that it has no support in Internet Explorer browsers.

ReadableStream

It representes a readable stream of data and it is the type of the body attribute of a fetch Response object.

fetch(url).then(response => console.log(response))

Response {
  body: ReadableStream {
    locked: false,
    [[Prototype]]: ReadableStream
  },
  bodyUsed: false,
  headers: Headers {},
  ok: true,
  redirected: false,
  ...
}

Note that it has no support in Internet Explorer browsers.

References

Twitter, LinkedIn