April 2020
Intermediate to advanced
716 pages
18h 55m
English
The remove method will allow the view component to delete a specific user from the database and use fetch to make a DELETE call. This, again, is a protected route that will require a valid JWT as a credential, similar to the read and update methods.
mern-skeleton/client/user/api-user.js:
const remove = async (params, credentials) => { try { let response = await fetch('/api/users/' + params.userId, { method: 'DELETE', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + credentials.t } }) return await response.json() } catch(err) { console.log(err) }}
The response from the server to the delete request will be returned to the component as a promise, as in the other methods. ...
Read now
Unlock full access