Skip to content
Tutorials Center
My learning

Topics

AJAX, JSON and Web APIs Tutorial

Learn AJAX, JSON and Web APIs step by step: 39 lessons in 8 chapters with examples, quizzes, diagrams and projects.

Start learning →

of lessons completed

Web APIs and AJAX Basics

  1. 1 What Is AJAX? Learn what AJAX is, how background requests differ from full page loads, and how XMLHttpRequest evolved into fetch(). Includes live examples.
  2. 2 HTTP for AJAX Developers The HTTP basics every AJAX developer needs: methods, URLs, status codes, headers, bodies, idempotency and caching, with Request and Response demos.
  3. 3 Web APIs and REST in Practice Understand web APIs and REST conventions: endpoints, resources, query strings, pagination, versioning and how to read API documentation.

JSON

  1. 4 JSON Syntax and Data Types Learn JSON syntax and its six data types, how JSON differs from JavaScript object literals, what it cannot hold and the most common syntax errors.
  2. 5 JSON.parse and JSON.stringify Convert JSON text to JavaScript values and back with JSON.parse and JSON.stringify. Learn pretty-printing, indentation and safe error handling.
  3. 6 Revivers, Replacers and toJSON Transform data while parsing and serializing JSON: revivers, replacer functions and toJSON. Handle dates, Map, Set, BigInt and circular references.
  4. 7 Converting JSON to and from CSV, Map, Set, Blob and Spreadsheets Move data between JSON and other shapes: Map and Set, CSV with correct quoting, Blob and File objects, downloads, and spreadsheet-friendly exports and imports.
  5. 8 Working with Nested JSON Navigate deep JSON safely with optional chaining and destructuring, reshape API results with map, filter and reduce, read NDJSON, and keep payloads fast.
  6. 9 Validating JSON Data Never trust API data. Write hand-made validators and type guards, learn the core ideas of JSON Schema, and run a pinned Ajv validator from a CDN.
  7. 10 JSON-LD and Embedding JSON in HTML Add JSON-LD structured data to a page, read it with JavaScript, and embed application data as a JSON data island without opening an XSS hole.
  8. 11 Reading and Writing JSON in Python, Java and PHP Back Ends See how a back end reads and writes the JSON your front end sends: json in Python, Jackson in Java, json_encode and json_decode in PHP, and how types match across the wire.

Fetch Fundamentals

  1. 12 Your First fetch() Request Make your first fetch() request: understand the promise and the Response, read JSON and text, compare .then with await, and practice with data URLs and a mock fetch.
  2. 13 The Response Object Explore the fetch Response: ok, status, statusText, headers, url and redirected, the body readers, why a body can be read only once, and how clone() helps.
  3. 14 Handling Errors in fetch Learn why fetch does not reject on 404 or 500, how to check response.ok, tell network failures from HTTP errors, parse error bodies and show friendly messages.
  4. 15 Sending Data: POST, PUT, PATCH, DELETE Send data with fetch: set the method, send JSON, form-encoded and FormData bodies, set Content-Type, use Request objects, and see what the server receives.
  5. 16 Headers, Auth and CORS Basics Learn the Headers class, Accept and Authorization headers, why API keys must not live in front-end code, and how simple and preflighted CORS requests work.

Async Patterns for Requests

  1. 17 Async/Await for Requests Run API requests in sequence or in parallel with async/await, and choose between Promise.all, allSettled, any and race, with live examples and error handling.
  2. 18 Cancelling Requests and Timeouts Cancel fetch requests with AbortController, add timeouts with AbortSignal.timeout, combine signals with any(), and stop stale search results from winning.
  3. 19 Retries, Backoff and Resilience Learn when to retry failed requests, how exponential backoff with jitter works, why idempotency matters, how to honor 429 Retry-After, and build a fetch wrapper.
  4. 20 Caching and Polling Cache API responses in memory, understand HTTP cache headers and ETag, poll for updates without waste, pause when the tab is hidden, and use stale-while-revalidate.

Building AJAX User Interfaces

  1. 21 Rendering API Data in the DOM Turn fetched JSON into safe DOM nodes, understand textContent versus innerHTML, use the template element, and show loading, empty and error states.
  2. 22 Submitting Forms with AJAX Submit HTML forms without a page reload: stop the default submit, read FormData, send JSON, show validation errors, disable the button and track uploads.
  3. 23 File Uploads and Progress Bars Upload files with FormData and fetch, validate them first, show real upload progress with XMLHttpRequest, queue many files, split big files into chunks and cancel an upload.
  4. 24 Live Search, Pagination and Infinite Scroll Build search-as-you-type with debouncing, drop stale results with AbortController, and load long lists by page, offset, cursor or infinite scroll.

Beyond Fetch

  1. 25 XMLHttpRequest and Legacy AJAX Understand XMLHttpRequest: readyState, load and progress events, timeouts and uploads, how to convert XHR code to fetch, and why JSONP is obsolete.
  2. 26 GraphQL Requests with fetch Call a GraphQL API from the browser with plain fetch - query, variables and operationName, the data and errors response shape, mutations, partial results and REST comparison.
  3. 27 Streaming and Real-Time APIs Read response streams with fetch, listen to Server-Sent Events, open WebSockets, share messages between tabs with BroadcastChannel and pick the right tool.
  4. 28 Beacons, keepalive and Sending Data on Page Exit Send analytics and saved state reliably when a user leaves the page: navigator.sendBeacon, fetch with keepalive, the visibilitychange event, size limits and a batching queue.
  5. 29 AJAX Security Protect AJAX apps: stop XSS from API data, defend against CSRF with SameSite cookies, avoid CORS mistakes, store tokens wisely and keep secrets off the client.
  6. 30 OAuth, Tokens and Sessions for API Calls Authenticate API calls from the browser - sessions versus bearer tokens, access and refresh tokens, a safe refresh wrapper for fetch, token storage trade-offs and the OAuth PKCE flow.
  7. 31 Debugging Network Requests Debug AJAX problems fast: read the DevTools Network panel, inspect headers and payloads, diagnose CORS, 404, mixed content and Content-Type errors, and test with fakes.

Projects

  1. 32 Project: User Directory Build a searchable, sortable user directory that loads JSON with fetch, shows loading and error states, retries, and opens a detail view. Every stage runs live.
  2. 33 Project: Weather Dashboard Build a weather dashboard against a mock forecast API: units toggle without refetching, an in-memory cache, stale data on failure, a retry button and live announcements.
  3. 34 Project: To-Do App with a Mock Backend Build a to-do app on an in-memory REST-style API: CRUD with fetch, optimistic updates with rollback, a request log and error toasts. Compare the two update styles live.
  4. 35 Project: A Reusable API Client Build a small reusable API client around fetch: base URL, JSON handling, typed errors, timeouts, retries with backoff and hooks. Runs live against a scripted fake server.

Practice and Review

  1. 36 Practice Exercises with Solutions Twelve graded AJAX, JSON and fetch exercises with hints and runnable solutions: parsing, errors, POST, parallel requests, safe rendering, abort, timeouts, retries and pagination.
  2. 37 Mock REST APIs with JSON Server Create a fake REST API from one db.json file with JSON Server, learn its routes, filters, sorting and pagination, and call it with fetch, with a runnable in-browser stand-in.
  3. 38 AJAX, JSON and Fetch Interview Questions 26 AJAX, JSON and fetch interview questions with concise answers and code: fetch vs XHR, CORS, error handling, race conditions, security, plus live puzzles.
  4. 39 AJAX, JSON and Fetch Cheat Sheet A compact cheat sheet for AJAX, JSON and fetch: request options, status codes, headers, JSON method rules, safe request patterns and the pitfalls that bite most often.