hono icon indicating copy to clipboard operation
hono copied to clipboard

Arrayed routes (multiple routes in single function)

Open morpig opened this issue 2 years ago • 1 comments

What is the feature you are proposing?

Hi,

Hono currently supports multi methods but not multi routes.

app.on(['PUT', 'DELETE'], '/post', (c) => c.text('PUT or DELETE /post'))

I would like to see support with the following:

app.get(['/hello', '/jp/hello', '/en/hello'], (c) => c.text('Hello!'))

Would be great for localisation/i18n use, etc. Thanks!

morpig avatar Jan 05 '24 05:01 morpig

Hi @morpig

Indeed, we would like to have that feature. However, type-solving and handling of path parameters are difficult.

So we do not plan to implement it at this time. Instead, although verbose, please use the following method, for example.

import { Hono } from 'hono'
import { createFactory } from 'hono/factory'

const app = new Hono()

const factory = createFactory()
const handler = factory.createHandlers((c) => c.text('Hi'))
app.get('/hello', ...handler)
app.get('/:lang{(en|jp)}/hello', ...handler)

yusukebe avatar Jan 08 '24 15:01 yusukebe