REST is an acronym for Representational State Transfer. It is web standards architecture and HTTP Protocol. The REST architectural style describes six constraints that were originally communicated by Roy Fielding in his doctoral dissertation and defines the basis of RESTful-style as:
- Uniform Interface
- Stateless
- Cacheable
- Client-Server
- Layered System
- Code on Demand (optional)
RESTful applications use HTTP requests to perform Create, Read, Update and Delete operations.
- Node.js
- MongoDB
- Text editor(Visual Studio, Atom, Sublime, etc)
- Postman
We are working on creating REST API's. Let's work on creating RESTful todo List API. Basically, creating CRUD (Create, Read, Update and Delete) operations.
NodeJs and MongoDB should be installed in the system.
Version installed in the system can be tested out using the following commands:
npm -v
mongo --version
type command 'mongod' in the terminal
'npm run start' in another terminal
- GET - http://localhost:3000/tasks, initially you will see '[]' empty array.
- POST - http://localhost:3000/tasks and select 'x-www-form-urlencoded' and enter 'name' as key and 'My first todo list' as value.
- GET - http://localhost:3000/tasks, initially you will see the list added in the 2nd step.
- GET - http://localhost:3000/tasks/:id, Provides an individual task present in the complete list.
- PUT - http://localhost:3000/tasks/update/:id, send a name in the request body.
- DELETE - http://localhost:3000/tasks/delete/:id, deletes the record from the list