Looking for tips about best practices
hey everyone, question
trying to use factories with my routes
factory.handlers should contain one method ?
or a lot of methods
I mean like that
should I define a handler for each method? or a global handler like i'm doing
for eg
and use my handlers in routes like that
4 Replies
i would recommend writing your handlers (and middleware) inline until you have a reason to abstract them out
the
createhandlers
factory is mainly for combining multiple (especially middleware) into a single function
the examples above actually limit your ability to take advantage of hono type inference, and will slow down your typescript server
in the long term, that level of abstraction will also make your code more difficult to maintainCan't get what you mean by "inline", you mean directly in the router function ?
exactly
that's the recommended way to write hono apps
even on a big scale you may not need to use factories
I assume the best time to use factories, is after refactoring the codebase
cause by then, you'd have an idea of what you are actually improving