Skip to content

Instantly share code, notes, and snippets.

@ma-9
Created December 2, 2019 17:55
Show Gist options
  • Save ma-9/c86a450ca9ea254f1309edbefa176e4b to your computer and use it in GitHub Desktop.
Save ma-9/c86a450ca9ea254f1309edbefa176e4b to your computer and use it in GitHub Desktop.
Sending Data to Mongoose using RESTful API
const newUser = {
name,
email,
password
};
try {
const config = {
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json'
}
};
const body = JSON.stringify(newUser);
const res = await axios.post('/api/users', body, config);
console.log(res.data);
} catch (err) {
console.error(err.message);
}
setFormData({
name: '',
email: '',
password: '',
password2: ''
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment