CS396: Spring 2021

Intro to Web Development

CS396: Spring 2021

Schedule > Using the fetch API

Week 5: Mon, Apr 26
Exercise Files

In this lesson, we’ll be applying what you’ve been learning about templates and event handlers to data that is queried dynamically from a server. We will do this using AJAX, and specifically using the fetch API. Please do assigned readings to see examples of how you might use fetch to issue GET, POST, PATCH, PUT, and DELETE requests to a server.

In the examples discussed in the readings, both the “then()” and “await/async” techniques are shown. Recall that there is no meaningful difference (under the hood) between the two approaches. I think this StackOverflow post is a nice summary of the distinctions between the two. To review promises, also take a look at Lesson 6.

Slides

Lecture Video(s)

Readings

  1. Lazaris, Louis (2020). Fetch API Tutorial for Beginners: How to Use Fetch API.
  2. fetch GET examples.
    Note: this example (and subsequent ones) demonstrate both "then" "async/await" techniques.
  3. fetch POST examples.
  4. fetch PUT examples.
    Note: PATCH works the same way as PUT. Recall that PATCH only updates specific attributes of a resource while PUT replaces the entire resource with a new version.
  5. fetch DELETE examples.