Federico Lenzi
Federico Lenzi

Reputation: 1612

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?

Upvotes: 6

Views: 3054

Answers (1)

vinayr
vinayr

Reputation: 11234

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

Upvotes: 14

Related Questions