Created
January 30, 2021 06:15
-
-
Save thawkin3/f5c4b3d7781c88d731bec7d8a2954fa1 to your computer and use it in GitHub Desktop.
JS snippet to post a new joke rating using the REST API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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