Skip to content

Instantly share code, notes, and snippets.

@thawkin3
Created January 30, 2021 06:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thawkin3/f5c4b3d7781c88d731bec7d8a2954fa1 to your computer and use it in GitHub Desktop.
Save thawkin3/f5c4b3d7781c88d731bec7d8a2954fa1 to your computer and use it in GitHub Desktop.
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