Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js Restify - Simple service

I'm trying to make a server which stores Json posts, here is the server so far:

var restify = require('restify');
var server = restify.createServer();
server.post('/message/', function create(req, res, next) {
    console.log(req.params)
    return next();
});

server.listen(8080, function() {
    console.log('%s listening at %s', server.name, server.url);
});

I'm using the Restify client to make the posts

var restify = require('restify');

var client = restify.createJsonClient({
  url: 'http://localhost:8080',
  version: '*'
});

client.post('/message/', { hello: 'world' }, function(err, req, res, obj) {
  console.log('%d -> %j', res.statusCode, res.headers);
  console.log('%j', obj);
});

The problem is that req.params is empty. What's missing?

like image 905
Federico Lenzi Avatar asked Oct 16 '12 23:10

Federico Lenzi


1 Answers

Before server.post do server.use(restify.bodyParser());

like image 60
vinayr Avatar answered Nov 15 '22 06:11

vinayr