Make sure MySQL is installed and running on the system. Create a api
table and run the query:
CREATE TABLE `users` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(30) DEFAULT '',
`username` varchar(50) DEFAULT '',
`email` varchar(50) DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Clone, install, and start up the app.
git clone https://github.com/taniarascia/node-api.git
cd node-api
npm install
node app.js
Navigate to http://localhost:3002
.
Use node post.js
to send a POST
request through, or use curl
to do all HTTP CRUD requests.
curl http://localhost:3002/users
curl http://localhost:3002/users/1
curl --data "name=Tania&[email protected]&username=floppydiskette" http://localhost:3002/users
curl -X PUT -d "name=Tania" -d "[email protected]" -d "username=taniarascia" http://localhost:3002/users/1
curl -X "DELETE" http://localhost:3002/users/1