Installing Node.js
For create the application I installed node.js and its package manager npm. For doing that I just typed:
$ sudo aptitude install nodejs npm
My actual linux installation (obsolete):
$ cat /etc/issue Ubuntu 10.10 \n \l
My actual node.js packages are:
$ dpkg -l node\* npm ... ii nodejs 0.8.2-1chl1~maverick1 Node.js event-based server-side javascript engine ii nodejs-dev 0.8.2-1chl1~maverick1 Development files for Node.js ii npm 1.1.39-1chl1~maverick1 package manager for nodejs
Note: If you want to install an specific version, you can do it directly from the sources.
Downloading the code
$ git clone https://github.com/camposer/express-examples.git
Starting the server
$ cd express-examples $ cd sqlite $ node app Express server listening on port 3000
Running the app
Just enter in your browser: http://localhost:3000
Testing the REST services
You can test the REST services directly using CURL (installing it is as simple as enter: `sudo aptitude install curl`). Inside the app there is a script named curltest.sh
.
echo "getUsers" curl -X GET http://localhost:3000/rest/users; echo echo "getUserById" curl -X GET http://localhost:3000/rest/users/1; echo echo "addUser" curl -X PUT -H "Content-type:application/x-www-form-urlencoded" -d "name=rodolfo" http://localhost:3000/rest/users; echo echo "updateUser" curl -X POST -H "Content-type:application/x-www-form-urlencoded" -d "id=1&name=juan" http://localhost:3000/rest/users; echo echo "deleteUser" curl -X DELETE -H "Content-type:application/x-www-form-urlencoded" -d "id=1" http://localhost:3000/rest/users; echo
No comments:
Post a Comment