Skip to content

Instantly share code, notes, and snippets.

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 => === responseData.jokeId)
jokeToUpdate && jokeToUpdate.ratings.push(responseData)
.finally(() => {
ratingInput.checked = false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment