Take 10 minutes to research the following in breakout groups. When you get back, I'm gonna call on some people to answer and explain.
1. What does the fetch api do?
Allows us to access data from an api. GET, POST, PATCH, PUT, DELETE
2. What does .fetch() return?
A Promise (JS Object that represents the eventual completion of an action)
3. What does .then() do? What is the method called on? What does it return?
Method called on a Promise, runs when Promise is returned successfully(resolves); returns another Promise
4. What does .catch() do? What is the method called on? What does it return?
Called on a Promise; runs when Promise is rejected; also returns another Promise
And tackle this diagram:
someAsyncFunction() // What does this return?
A promise
.then( (1) ) // When does this run? What does it return?
Runs when the promise is resolved. Returns a response that needs to be parsed
.then( (2) ) // When does this run? What does it return?
Runs after parsing the response. Returns data we want to manipulate in our app.
.catch( (3) ) // When does this run? What does it return?
Runs if any promise is rejected. Returns what you want to do with that error.
// What goes in place of (1), (2), and (3)?
callback functions; evaluate to some value(x); that value(x) becomes the resolved value(y) of the Promise that .then/.catch returns