Node.js Restify - Simple service
Asked Answered
W

1

6

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?

Waft answered 16/10, 2012 at 23:29 Comment(0)
D
14

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

Discography answered 17/10, 2012 at 2:53 Comment(2)
I started to use Express because it has better documentationWaft
@Federico Restify is only good if you want DTrace and even then, there are plenty of third party DTrace libs to tack on to Express... good choice in switching.Blades

© 2022 - 2024 — McMap. All rights reserved.