This works for me (code called from node js repl):
const axios = require("axios");
axios
.put(
"http://localhost:4000/api/token",
"mytoken",
{headers: {"Content-Type": "text/plain"}}
)
.then(r => console.log(r.status))
.catch(e => console.log(e));
Logs: 200
And this is my request handler (I am using restify):
function handleToken(req, res) {
if(typeof req.body === "string" && req.body.length > 3) {
res.send(200);
} else {
res.send(400);
}
}
Content-Type header is important here.