Handling POSTed data in Restify and Node.js

When creating a webservice using Restify, you may want to be able to handle data POSTed to your API.  Have a look at our article about creating a RESTful webservice in node.js for the basics on setting up the server and routing the requests.  In that article you see that you use the following code to route a POST request to your handler function.

server.post('/my_post',my_post_handler);

OK, so now all POST requests will be sent to the my_post_handler function.  The problem is that the data being POSTed to the server needs to be properly parsed so that it can be easily handled by your script.  This is where the Restify plugin bodyParser comes into play.  The plugin can be used easily by simply adding the following line of code before your post handler.  So setting up your routes would look something like this.

Read moreHandling POSTed data in Restify and Node.js

Creating a RESTful webservice with Node.JS

We wanted to create a scalable REST webservice that could be used to access some backend data in our application. I had heard about Node.js but hadn’t actually used it for anything.  This seemed like the ideal situation to give it a try.  Node.js seems to have been built on the concept of having it run on semi-reliable servers and to operate in a “multi-node” style architecture, which is exactly what we want to do. In this post I’ll show you how to build a RESTful webservice using Node.js.

So… I bought and read the “The Node Beginner Book” (ebook) by Manuel Kiessling which was a very good introduction to node.js.  It also provided a bit of javascript intro and is very relevant to building a RESTful web service as it talks about concepts that can be directly applied.  I’d recommend it for people new to Node.js (but who already have a development background).

Read moreCreating a RESTful webservice with Node.JS