- First install npm dependencies of express and mongoose using
npm install
command. - Create database in your local computer using
node src/createDatabase.js
command. - Start the backend server using
npm start
ornode src/index.js
command.
-
GET http://localhost:3000/subscribers to get array of subscribers.
-
GET http://localhost:3000/subscribers/names to get array of subscribers with only name and subscribedChannel fields.
-
GET http://localhost:3000/subscribers/:id to get a subscriber by its unique id.
Note: If the wrong :id is entered in the url, then the client will encounter
400 Bad Request
status code indicating that the server cannot or will not process the request due to something that is perceived to be a client error.
- POST http://localhost:3000/subscribers to add a new subscriber to the database. Add the data in JSON format.
{
"name": "Dummny",
"subscribedChannel": "Channel"
}
- PUT http://localhost:3000/subscribers/:id to update the data of a subscriber by its unique id.
{
"name": "Update Name",
"subscribedChannel": "Update Channel"
}
- DELETE http://localhost:3000/subscribers/:id to delete a subscriber by its unique id.
app.use() is used to handle all the unwanted requests. It will return
404 Not Found
status code indicating that the requested resource could not be found but may be available in the future.