Answer the question
In order to leave comments, you need to log in
How to send a post request with express?
I ran into a problem, tell me what I'm doing wrong?
Most likely I do not understand how the controller works on the express, how can I fix this?
There is a server on express where the following controller is written:
exports.create = function (req, res) {
if (!req.body.text) {
res.status(422).send("'text' field must be present in json");
} else {
const written = db.get('todos')
.push({
id: uuidv1(),
text: req.body.text,
completed: false,
createdDate: new Date().getTime()
})
.last()
.write();
res.send(written);
}
};
export function createTask(value) {
return fetch(`todos/`, {
method: "POST",
mode: "no-cors",
headers: {
"Content-Type": "application/json",
Accept: "application/json"
},
body: JSON.stringify({ text: value })
}).then(res => res.json());
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question