April 2020
Intermediate to advanced
716 pages
18h 55m
English
We will update api-post.js by adding a create method to make a fetch call to the create API. The create fetch method will look as follows.
mern-social/client/post/api-post.js:
const create = async (params, credentials, post) => { try { let response = await fetch('/api/posts/new/'+ params.userId, { method: 'POST', headers: { 'Accept': 'application/json', 'Authorization': 'Bearer ' + credentials.t }, body: post }) return await response.json() } catch(err) { console.log(err) }}
This method, like the user edit fetch method, will send a multipart form submission using a FormData object that will contain the text field and the image file. Finally, we are ready to integrate this create new post feature in ...
Read now
Unlock full access