A simple API developed using the restify package to gain a basic insight of the how the package works.
To run the API, install the following:
- node.js v10.x or above
- npm v6.x or above
- curl v7.x or above
To manage multiple NodeJs versions, its recommended to use Node Version Manager.
-
Install required packages
npm install
-
Initiate the server
npm start
-
Add products to the store
curl -H "Content-Type: application/json" -X POST -d '{"id":101,"name":"Pizza"}' http://127.0.0.1:3000/api/products
-
Fetch details for all products
curl --request GET http://127.0.0.1:3000/api/products/
-
Update a product in the store
curl -H "Content-Type: application/json" -X PUT -d '{"name":"Sandwich"}' http://127.0.0.1:3000/api/products/101
-
Fetch details for a product
curl --request GET http://127.0.0.1:3000/api/products/101
-
Delete a product
curl --request DELETE http://127.0.0.1:3000/api/products/101
To use Postman, remember to set the Content-Type header to application/json and pass the data as raw JSON under the Body tab.