lundi 6 janvier 2020

Best practices for request response handling in express application

I have a REST API built on express (and using typescript) with following structure

  • app.ts
  • routes
  • controllers
  • models

Question : Which is the best place to handle/build the request/response? will that be in routes or controllers ?

I am divided between 2 approaches in mind

1 - Using routes for only mapping the corresponding method in controller, have request and response handling inside the controller class file

2 - Using the routes for handling request and building response based on response from the corresponding method in controller. In this way I can re-use controller methods from different routes when needed.

Any suggestions on which is the best approach ?

Aucun commentaire:

Enregistrer un commentaire