The quiz questions relate to this piece of code:
fetch("http://www.ajax.com/dinosaurs/13", {
method: "PATCH",
headers: {
"Content-Type": "application/json",
"Accept": "application/json"
},
body: JSON.stringify({
species: "Tyrannosaurus Rex",
name: "SUE"
})
}).then(response => response.json())
.then(data => slapItOnTheDom(data))
fetch("http://www.ajax.com/dinosaurs/13", {
method: "PATCH",
- What does the string passed in as the first parameter to
fetch
do? - What does the
method
key of the second parameter do? - Based on the values of the string, the value of the
method
key, and the REST standard, what will this fetch do in the API?
headers: {
"Content-Type": "application/json",
"Accept": "application/json"
},
- What is the "Content-Type" header for?
- What is the "Accept" header for?
- When do I need a "Content-Type" header?
- When do I need an "Accept" header?
body: JSON.stringify({
species: "Tyrannosaurus Rex",
name: "SUE"
})
- What data type does the value of the
body
key need to be? - What will the return value of
JSON.stringify
look like, based on the parameter shown here? - What purpose does the body of a
PATCH
request serve? - Should there be an ID in the object being passed to
JSON.stringify
? Why?
}).then(response => response.json())
- What are we calling
.then
on? - What is being passed to the
.then
method? - What is
response
? - What does
.json()
do? What does it return?
.then(data => slapItOnTheDom(data))
- What is
data
? - What does
slapItOnTheDom
probably do withdata
? - Is this optimistic rendering, pessimistic rendering, or neither?
- What does it mean that
fetch
is asynchronous? - Why does JavaScript use asynchronous code so much?