![Full-Stack React Projects](https://wfqqreader-1252317822.image.myqcloud.com/cover/866/36699866/b_36699866.jpg)
上QQ阅读APP看书,第一时间看更新
Creating a user
The create method will take user data from the view component, use fetch to make a POST call to create a new user in the backend, and finally return the response from the server to the component as a promise.
mern-skeleton/client/user/api-user.js:
const create = (user) => {
return fetch('/api/users/', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(user)
})
.then((response) => {
return response.json()
}).catch((err) => console.log(err))
}