Code:
const express = require('express')
const bodyParser = require('body-parser')
app = express()
app.use(bodyParser.json());
app.post('/', function (req, res)
{
res.send("Ok")
})
app.listen(7000)
Works:
curl -X POST localhost:7000/
Fails:
Cmd: curl -H "Content-Type: application/json" -d {"day":"Friday"} localhost:7000/
Error: SyntaxError: Unexpected token d in JSON at position 1
Any ideas?
Resolution:
The problems seems to be due to the fact I was doing this on Windows. The following commands worked.
curl -H "Content-Type: application/json" -d {"""day""":"""Friday"""}localhost:7000/
curl -H "Content-Type: application/json" -d {\"day\":\"Friday\"} localhost:7000/
curl -H "Content-Type: application/json" -d "{\"day\":\"Friday\"}" localhost:7000/