©  Caio Ribeiro Pereira 2016

Caio Ribeiro Pereira, Building APIs with Node.js , 10.1007/978-1-4842-2442-7_6

6. CRUDify API Resources

Caio Ribeiro Pereira

(1)São Vicente - SP, São Paulo, Brazil

In this chapter, we’ll continue to explore the new functions from Sequelize and also organize the API’s routes and some middlewares of Express. The create, read, update, delete (CRUD) will be built using the Tasks and Users models.

Organizing Task Routes

To start this refactoring, let’s explore the main HTTP methods to CRUDify our application. In this case, we are going to use the functions app.route("/tasks") and app.route("/tasks/:id") to define the path: "/tasks" and "/tasks/(task_id)".

These functions allow us to use nested functions, reusing the routes ...

Get Building APIs with Node.js now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.