Intro to Fetch + Promises
CSCI 344: Advanced Web Technologies
Spring 2026
Outline
Intro to “AJAX”
AJAX
3
Intro to Fetch
JavaScript’s Fetch API
4
What is a Promise?
Most requests happen in 2 Parts (w/2 Promises)
async function getData () {
const response = await fetch(url); // retrieves HTTP response object
const data = await response.json(); // retrieves the response body
}
Promises: Two Syntaxes > async await
Using the async / await technique. Instead of using “then()” the await keyword ensures that the next line doesn’t execute until the promise resolves.
const getBusinesses = async () => {
let url = 'https://www.apitutor.org/yelp/simple/v3/businesses/search?location=Asheville,+NC';
const response = await fetch(url);
console.log(response);
const jsonData = await response.json();
console.log(jsonData);
};
getBusinesses();
Promises: Two Syntaxes > “then” method
You can also use the promise’s “then” method, which will execute a callback function when the promise finishes its business...�
let url = 'https://www.apitutor.org/yelp/simple/v3/businesses/search?location=Asheville,+NC'
fetch(url)
.then(response => response.json()) // callback function
.then(data => console.log(data)); // callback function
Be aware of this approach, but it’s less common
Practice
Download today’s files: ��https://csci344.github.io/spring2026/course-files/lectures/lecture16.zip
Partner programming Activity
Outline
Summary (2 of 2)
When we come back from break
Read the Homework 3 Instructions �before coming to class