Skip to content
Myr

docs(readme): update

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Yusuke Wada · committed by Yusuke Wada · parent 6a7746d · Browse files · 1 file+27 added−17 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+27 added−17 removed

  • other:+27 added−17 removed

1 file+27 added−17 removed

modified:README.md+27 added-17 removed
554 unmodified lines
555556const app = new Hono({ router: new RegExpRouter() })557```558559## Routing Ordering559## Routing priority560561The routing priority is decided by the order of registration. Only one handler will be dispatched.561Handlers or middleware will be executed in registration order.562563```ts564app.get('/book/a', (c) => c.text('a')) // a565app.get('/book/:slug', (c) => c.text('common')) // common566```567568```http569GET /book/a ---> `a` // common will not be dispatched570GET /book/b ---> `common` // a will not be dispatched569GET /book/a ---> `a`570GET /book/b ---> `common`571```572573All scoring rules:573When a handler is executed, the process will be stopped.574575```ts576app.get('/api/*', 'c') // score 1.1 <--- `/*` is special wildcard577app.get('/api/:type/:id', 'd') // score 3.2578app.get('/api/posts/:id', 'e') // score 3.3579app.get('/api/posts/123', 'f') // score 3.4580app.get('/*/*/:id', 'g') // score 3.5581app.get('/api/posts/*/comment', 'h') // score 4.6 - not match582app.get('*', 'a') // score 0.7583app.get('*', 'b') // score 0.8576app.get('*', (c) => c.text('common')) // common577app.get('/foo', (c) => c.text('foo')) // foo578```579586```plain587GET /api/posts/123588---> will match => c, d, e, f, b, a, b589---> sort by score => a, b, c, d, e, f, g580```http581GET /foo ---> `common` // foo will not be dispatched582```583584If you have the middleware that you want to execute, write the code above the handler.585586```ts587app.use('*', logger())588app.get('/foo', (c) => c.text('foo'))589```590591If you want a "_fallback_" handler, write the code below the other handler.592593```ts594app.get('/foo', (c) => c.text('foo')) // foo595app.get('*', (c) => c.text('fallback')) // fallback596```597598```http599GET /bar ---> `fallback`600```601602## Cloudflare Workers with Hono603604Using [Wrangler](https://developers.cloudflare.com/workers/cli-wrangler/), you can develop the application locally and publish it with few commands.605
152 unmodified lines