// req.text (http://stackoverflow.com/questions/12497358/handling-text-plain-in-express-3-via-connect/12497793#12497793) app.use(function(req, res, next){ if (req.is('text/*')) { req.text = ''; req.setEncoding('utf8'); req.on('data', function(chunk){ req.text += chunk; }); req.on('end', next); } else { next(); } });
app.post('/cot', jsonParser, (req, res) => { // check to see if valid JSON is being sent if (!req.body.jwt || !req.is('application/json')) return res.status(400).send('Bad Request - Please send me valid JSON to process'); fetch('https://api.ciscospark.com/v1/jwt/login', { method: 'POST', headers: { 'Authorization': req.body.jwt }, }) .then(res => res.json()) .then(json => { console.log("Got OAuth from Spark = " + JSON.stringify(json)); res.json(json); }); });
// receive a text callback from bandwidth app.post('/receiveText', auth, (req, res, next) => { if (!req.is('application/json')) { res.sendStatus(415); return next(); } const catapultData = req.body; console.log(catapultData); res.send("received!") })
app.post('/todos', function (req, res) { if (!req.is('json')) { res.status(415).send('Payload must be JSON'); } console.log(util.inspect(req.body)); var newTodo = req.body; newTodo.id = nextId; todos.push(newTodo); nextId++; console.log(util.inspect(todos)); res.status(201).json({data: newTodo}); // setTimeout(() => res.status(201).json({data: newTodo}), 2000); //res.status(500).json(newRating); // return an error to see how the client behaves... });
if (!(request.is('multipart/form-data') || request.headers['x-file-name'])) {
if (!req.body.name || !req.body.email || !req.is('application/json')) return res.status(400).send('Bad Request - Please send me valid JSON to process');
if (!(request.is('multipart/form-data'))) { response.status(415).send('Unsupported media type'); return;
app.post('/todos', function (req, res) { if (!req.is('json')) { res.status(415).send('Payload must be JSON'); } console.log(util.inspect(req.body)); var newTodo = req.body; newTodo.id = nextId; todos.push(newTodo); nextId++; console.log(util.inspect(todos)); res.status(201).json({data: newTodo}); // setTimeout(() => res.status(201).json({data: newTodo}), 2000); //res.status(500).json(newRating); // return an error to see how the client behaves... });
if (!(request.is('multipart/form-data') || request.headers['x-file-name'])) {
if (!(request.is('multipart/form-data') || request.headers['x-file-name'])) {