Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
JS snippet to post a new joke rating using the REST API
fetch('/ratings', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(postData),
})
.then(response => response.json())
.then(responseData => {
const jokeToUpdate = jokes.find(joke => joke.id === responseData.jokeId)
jokeToUpdate && jokeToUpdate.ratings.push(responseData)
})
.finally(() => {
ratingInput.checked = false
displayNextJoke()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment