After creating a simple web server, we can build a simple RESTful. REST stands for Representational State Transfer. It uses primitive HTTP operations to maintain communication between the server and the client. In this section, I implement RESTful using Express for Node.js. This library can cut your development time to build a web application.
For further information about Express, please visit http://expressjs.com. We also need body-parser to work with JSON data. JSON (JavaScript Object Notation) is a lightweight data-interchange format and easy to read and write. The following is a sample of JSON data:
{ name: 'foo', email: '[email protected]', leve: 3 }
We are going to use JSON to exchange data between the server and the client.
To install Express and body-parser, you can use npm
. Type the following commands:
$ npm install express $ npm install body-parser
For testing, we build a simple RESTful app, which serves HTTP GET
JSON. Create a file named myrest...