Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does one access data posted within restify 1.x.x?

Tags:

rest

post

node.js

I'm posting data to a restify API, but cannot find any currently examples for how to access the posted data. How does this work?

like image 216
JMHNilbog Avatar asked Feb 17 '12 14:02

JMHNilbog


People also ask

What is the use of Restify?

restify is a node. js module built specifically to enable you to build correct REST web services. It intentionally borrows heavily from express as that is more or less the de facto API for writing web applications on top of node. js.

What is Restify framework?

A Node. js web service framework optimized for building semantically correct RESTful web services ready for production use at scale. restify optimizes for introspection and performance, and is used in some of the largest Node. js deployments on Earth.


1 Answers

I found the answer. One of the included plugins needs to be activated, restify.bodyParser. The data may then be found in either req.params (default) or req.body (mapParams: false), depending on the settings (look specifically at BodyParser section).

Example:

server.use(restify.bodyParser({ mapParams: false })); // mapped in req.body 

Or:

server.use(restify.bodyParser()); // mapped in req.params 
like image 178
JMHNilbog Avatar answered Oct 14 '22 14:10

JMHNilbog