Replies: 1 comment 1 reply
-
I have discovered this works, but unclear if best practice / maximum type safety. // src/index.ts
import { Hono } from 'hono'
import { UserController } from './User.controller.ts'
const app = new Hono()
app.route('/user', UserController);
export default app // src/User.controller.ts
import { createFactory } from 'hono/factory';
import { logger } from 'hono/logger';
export const UserController = createFactory().createApp()
.get('/', logger(), (c) => { return c.text('Hello Hono!!!!!'); })
.get('/:id', logger(), (c) => { return c.text(`hi lil user ${c.req.param('id')}`); }); |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Reading through the docs it's recommended to use the
createFactory()
helper to create rails-style controllers / route handlers.However, the docs do not include examples of what this looks like.
The best practices also suggests using
createFactory()
for this purpose but does not include example of defining >1 handler with the factory.Would someone please provide an example of how to create colocated handlers (rails-like) with full type safety? Also, when to use
factory.createHandlers
vs when to usefactory.createApp
?Beta Was this translation helpful? Give feedback.
All reactions