Skip to content

Latest commit

 

History

History
32 lines (23 loc) · 1.45 KB

README.md

File metadata and controls

32 lines (23 loc) · 1.45 KB

The-Fetch-API

Learning about fetch API
This project is to explore the fetch API. In this project, fetching the data from local text file, local json file and external API are demonstrated.

For demonstrating fetching data from external API, https://api.github.com/users API is used.


  • Fetch API is a newer standard for dealing with HTTP requests
  • The Fetch API provides a JavaScript interface for accessing and manipulating parts of the HTTP pipeline, such as requests and responses. It also provides a global fetch() method that provides an easy, logical way to fetch resources asynchronously across the network.
  • It is now a part of window object
  • Fetch returns promises.
  • When you get a response from a promise, you have to use .then()
  • If there is some kind of error, then we can do .catch()

Example

Getting a data from a text file which is located locally

Getting data from a JSON file which is located locally

Getting data from an external API


Update to the project

  • In app.js, arrow functions are used.
  • Arrow functions use lexical this. So you don't have to worry about the scope of the function