I am trying to do a POST request through fetch
in reactjs. I went through some docs but my error not solved.Can anyone please help me out?
Here is my reactjs code:
handleSubmit(e) {
e.preventDefault();
var self = this;
const payload = {
id: 111,
studentName: 'param',
age: 24,
emailId: 2
};
fetch({
method: 'POST',
url: 'http://localhost:8083/students',
body: payload,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
})
.then(function(response) {
return response.json()
}).then(function(body) {
console.log(body);
});
}
}
If any one familiar with reactjs, just give a simple example how to call post request.Either by using fetch
or axios
.