AJAX, Promises, and Fetch (Communicating with APIs)

  • What is AJAX? Async JavaScript and XML
  • What is blocking (sync) vs non-blocking code (async)?

How do we handle async code?

Callback Hell

  • Nested callbacks within nested callbacks
  • Triangle shape
  • Really hard to read and manage

Welcome Fetch

Promises and what are they

  • MDN documentation
  • Practice with: http://localhost:300/hello/1
  • pending
  • fulfilled (resolved/rejected)
  • How to unwrap a promise using .then
  • At Flatiron, we will work with promises via Fetch rather than creating our own Promises

Promise chaining

  • .then().then()
  • Easier to read, easier to manage

Reminder:

  • First FSPs this Friday
  • Even if you're not in the first group, start it asap, talk to the coaches