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 tosession
:/session/login
(GET),/session/logout
(POST on session), and/session/signup
(POST). -
go through
/user
with fullCRUD
functionality -
from
/user
go through a/accounts
,/transactions
which from each we can get a single account and transaction, and at leastC
andR
andU
andD
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.).