ExpressJS' router has equivalent methods to handle HTTP methods. In other words, the HTTP methods POST, GET, PUT, and DELETE can be handled by this code:
/* Add a new user */ app.post('/users', (request, response, next) => { }) /* Get user */ app.get('/users/:id', (request, response, next) => { }) /* Update a user */ app.put('/users/:id', (request, response, next) => { }) /* Delete a user */ app.delete('/users/:id', (request, response, next) => { })
It's good to think of every URL as a noun and because of that a verb can act on it. In fact, HTTP methods are also known as HTTP verbs. If we think about them as verbs, when a request is made to our RESTful API, they can be understood as:
- Post a user
- Get a user
- Update...