Created
December 2, 2019 17:55
-
-
Save ma-9/c86a450ca9ea254f1309edbefa176e4b to your computer and use it in GitHub Desktop.
Sending Data to Mongoose using RESTful API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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