How many routers are we able to have?

Question

How many routers are we able to have?

Answer

That will depend on how we are handling data and how many different routes we have. There is no real cap on the number of routers to set, for example if we were to make a banking app, then our app’s front-end requests to our servers will probably have to…

  • go through /login, /signup, and /logout this could be set as one router to session: /session/login(GET), /session/logout(POST on session), and /session/signup(POST).

  • go through /user with full CRUD functionality

  • from /user go through a /accounts, /transactions which from each we can get a single account and transaction, and at least C and R and U and D on some actions.

  • we can also have a /services route that can handle bank related requests like opening a new account or contacting customer service.

As we can see, there we have the possibility to divide our routes into at least 3 routers(/sessions, /user, and /services), but for /user we might also want to nest three routers, one for the user’s information, a second one to handle /accounts requests, and a third for /transactions.

We can have as many routers as we need in an app, it will always be related to how our server will receive requests, what kind of data will be in our responses, and from where is that data coming from (database, other API, etc.).

3 Likes