Fetch

The edit API is called in the view using a fetch method that takes the form data and sends it with the request to the backend along with user credentials.

mern-vrgame/client/game/api-game.js:

const update = (params, credentials, game) => {  return fetch('/api/games/' + params.gameId, {    method: 'PUT',    headers: {      'Accept': 'application/json',      'Content-Type': 'application/json',      'Authorization': 'Bearer ' + credentials.t    },    body: JSON.stringify(game)  }).then((response) => {    return response.json()   }).catch((err) => {    console.log(err)   }) }

Get Full-Stack React Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.