Update readme
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 d2058b5 · Browse files · 2 files·+24 added−19 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+24 added−19 removed
- other:+24 added−19 removed
Provenance
- Commit
a41c57d- Tree
ddce895- Author
Yusuke Wada <yusuke@kamawada.com>- Committer
Yusuke Wada <yusuke@kamawada.com>- Parent
d2058b5
2 files changed+24 added−19 removed
modified:example/basic/index.js+3 added-6 removed
9 unmodified lines10111213141516171818192021222319202122239 unmodified lines next() res.headers.append('X-message', 'This is addHeader middleware!')}
// Mount middlewareapp.use('*', logger)app.use('/hello', addHeader)
// Routingapp.get('/', () => { return new Response('Hono!!')})app.get('/hello', () => { return new Response('This is /hello')})app.get('/', () => new Response('Hono!!'))app.get('/hello', () => new Response('This is /hello'))
// addEventListenerapp.fire()modified:README.md+21 added-13 removed
3 unmodified lines45678891011125 unmodified lines181920212222232425263 unmodified lines30313233343534353637383738394041424344454748494647484950515253545556575859606162636418 unmodified lines83848586818283878889909192934 unmodified lines98991001019610210310410510620 unmodified lines1271281291301311321331341351367 unmodified lines3 unmodified lines
```jsconst app = Hono()
app.get('/', () => 'Hono!!')app.get('/', () => new Response('Hono!!'))
app.fire()```
5 unmodified lines- Optimized for Cloudflare Workers.
## Install
```sh```$ yarn add hono```
or3 unmodified lines```
## Methods
- app.**HTTP_METHOD**(path, ...callback)- app.**all**(path, ...callback)- app.**HTTP_METHOD**(path, callback)- app.**all**(path, callback)- app.**route**(path)- app.**before**(...callback)- app.**after**(...callback)- app.**use**(path, middleware)
## Routing
### Basic
`app.HTTP_METHOD`
```jsapp.get('/', () => 'GET /')app.post('/', () => 'POST /')app.get('/wild/*/card', () => 'GET /wild/*/card')// HTTP Methodsapp.get('/', () => new Response('GET /'))app.post('/', () => new Response('POST /'))
// Wildcardapp.get('/wild/*/card', => { return new Reponse('GET /wild/*/card')})```
`app.all`
```js// Any HTTP methodsapp.all('/hello', () => 'ALL Method /hello')```
### Named Parameter18 unmodified lines
```jsapp .route('/api/book') .get(() => 'GET /api/book') .post(() => 'POST /api/book') .put(() => 'PUT /api/book') .get(() => {...}) .post(() => {...}) .put(() => {...})```
## Middleware
4 unmodified lines}
const addHeader = (req, res, next) => { next() res.headers.add('X-message', 'This is addHeader middleware!') res.headers.add('x-message', 'This is middleware!')}
app = app.use('*', logger)app = app.use('/message/*', addHeader)20 unmodified lines```
## Related projects
- koa <https://github.com/koajs/koa>- express <https://github.com/expressjs/express>- itty-router <https://github.com/kwhitley/itty-router>- Sunder <https://github.com/SunderJS/sunder>- goblin <https://github.com/bmf-san/goblin>
7 unmodified lines