Hi I am trying to send a request with fetch method. Normally I will use axios to send request. Now i am trying something new in typescript.
Here is the axios version of the request. Its working fine. The email got sent
axios
.post('http://localhost:3000/login/email', { email: emailToBeSent })
.then(res => {
alert(emailToBeSent);
})
.catch(err => {
alert(emailToBeSent + 'error not sent');
});
But when i try with the fetch, mail won't be sent but response return success but its indicating bad request
const data = { email: emailToBeSent };
fetch('http://localhost:3000/login/email', {
method: 'POST', // or 'PUT'
body: JSON.stringify(data),
})
.then(response => {
console.log('Success:', response);
})
.catch(error => {
alert('Error:');
});
Can anyone suggest what I am missing here?
Here is the response
