FirstHack Learn
Log in Sign up free
Lessons in this course 0/6 All courses Web Development Basics

CSE

Progress0 / 6 lessons
  1. 1. How a web page reaches your screen
  2. 2. HTML structure and semantic tags
  3. 3. CSS: the box model, flexbox, and why layouts break
  4. 4. JavaScript: variables, functions and the DOM
  5. 5. Events and forms
  6. 6. fetch and working with JSON from an API

Courses › Web Development Basics

fetch and working with JSON from an API

Ask another server for data, wait for it properly, and show it on your page.

13 min read · Lesson 6 of 6 · Pro

What an API is

An API here means a URL that returns data instead of a page. You send a GET request, you get back JSON. No HTML, no styling, just facts.

JSON looks like a JavaScript object written as text:

JavaScript
const text = '{"name":"Ravi","year":2,"subjects":["DS","OS"]}';
const student = JSON.parse(text);

console.log(student.name);         // Ravi
console.log(student.subjects[1]);  // OS
console.log(JSON.stringify(student));

Rules JSON enforces that JavaScript does not: keys must be in double quotes, strings must use double quotes, no trailing comma, no comments.

fetch returns a promise

The rest of this lesson is Pro

The free lessons of Web Development Basics finish what they start — read those first if you have not. This one goes further, and it is part of the paid half.

A pass opens the paid lessons of every course, the mock test papers and the company-wise series. It ends on its own date; nothing renews by itself.

Get a pass — from ₹29 for 7 days

Already bought one? Log in.