docs: 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 bd29072 · Browse files · 1 file·+69 added−58 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+69 added−58 removed
- other:+69 added−58 removed
Provenance
- Commit
5de3a0c- Tree
4b95b12- Author
Yusuke Wada <yusuke@kamawada.com>- Committer
Yusuke Wada <yusuke@kamawada.com>- Parent
bd29072
1 file changed+69 added−58 removed
modified:README.md+69 added-58 removed
1 unmodified line2 3 [](https://github.com/yusukebe/hono/actions)4 [](https://github.com/yusukebe/hono/blob/master/LICENSE)5 [](https://www.npmjs.com/package/hono)6-[](https://www.npmjs.com/package/hono)6+[](https://www.npmjs.com/package/hono)7 [](https://www.npmjs.com/package/hono)8 [](https://github.com/yusukebe/hono/pulse)9 [](https://github.com/yusukebe/hono/commits/master)10 11-Hono[炎] - _**means flame🔥 in Japanese**_ - is small, simple, and ultrafast web framework for a Service Workers API based serverless such as Cloudflare Workers and Fastly Compute@Edge.11+Hono[炎] - _**means flame🔥 in Japanese**_ - is small, simple, and ultrafast web framework for Service Worker based serverless applications like Cloudflare Workers and Fastly Compute@Edge.12 13 ```js14 import { Hono } from 'hono'15 const app = new Hono()4 unmodified lines20 ```21 22 ## Features23 24-- **Ultra fast** - the router is implemented with Trie-Tree structure. Not use loops.25-- **Zero dependencies** - using only Web standard API.26-- **Middleware** - builtin middleware, and you can make your own middleware.24+- **Ultrafast** - the router does not use linear loops.25+- **Zero-dependencies** - using only Web standard API.26+- **Middleware** - builtin middleware and your own middleware.27 - **Optimized** - for Cloudflare Workers.28 29 ## Benchmark30 9 unmodified lines40 ```41 42 ## Hono in 1 minute43 44-Below is a demonstration to create an application of Cloudflare Workers with Hono.44+A demonstration to create an application of Cloudflare Workers with Hono.45 46 47 48 Now, the named path parameter has types.1 unmodified line50 51 52 ## Install53 54-You can install Hono from npm registry:54+You can install Hono from the npm registry.55 56 ```sh57-yarn add hono57+$ yarn add hono58 ```59 60 or61 62 ```sh63-npm install hono63+$ npm install hono64 ```65 66 ## Methods67 68-An instance of `Hono` has these methods:68+An instance of `Hono` has these methods.69 70 - app.**HTTP_METHOD**(path, handler)71 - app.**all**(path, handler)72 - app.**route**(path)4 unmodified lines77 ## Routing78 79 ### Basic80 81-`app.HTTP_METHOD`82-81 ```js82 // HTTP Methods83 app.get('/', (c) => c.text('GET /'))84 app.post('/', (c) => c.text('POST /'))1 unmodified line86 // Wildcard87 app.get('/wild/*/card', (c) => {88 return c.text('GET /wild/*/card')89 })92-```90 94-`app.all`95-96-```js91 // Any HTTP methods92 app.all('/hello', (c) => c.text('Any Method /hello'))93 ```94 12 unmodified lines107 app.get('/post/:date{[0-9]+}/:title{[a-z]+}', (c) => {108 const date = c.req.param('date')109 const title = c.req.param('title')110 ...111+})112 ```113 114 ### Nested route115 116 ```js117 const book = app.route('/book')123-book.get('/', (c) => c.text('List Books')) // => GET /book118+book.get('/', (c) => c.text('List Books')) // GET /book119 book.get('/:id', (c) => {125- // => GET /book/:id120+ // GET /book/:id121 const id = c.req.param('id')122 return c.text('Get Book: ' + id)123 })129-book.post('/', (c) => c.text('Create Book')) // => POST /book124+book.post('/', (c) => c.text('Create Book')) // POST /book125 ```126 127 ### no strict128 134-If `strict` is set `false`, `/hello`and`/hello/` are treated the same:129+If `strict` is set `false`, `/hello`and`/hello/` are treated the same. Default is `true`.130 131 ```js132 const app = new Hono({ strict: false })133 134 app.get('/hello', (c) => c.text('/hello or /hello/'))135 ```136 142-Default is `true`.143-137 ### async/await138 139 ```js140 app.get('/fetch-url', async (c) => {15 unmodified lines156 const app = new Hono()157 158 app.use('*', poweredBy())159 app.use('*', logger())167-app.use('/auth/*', basicAuth({ username: 'hono', password: 'acoolproject' }))160+app.use(161+ '/auth/*',162+ basicAuth({163+ username: 'hono',164+ password: 'acoolproject',165+ })166+)167 ```168 169 Available builtin middleware are listed on [src/middleware](https://github.com/yusukebe/hono/tree/master/src/middleware).170 171 ### Custom Middleware172 174-You can write your own middleware:173+You can write your own middleware.174 175 ```js176 // Custom logger177 app.use('*', async (c, next) => {11 unmodified lines189 ```190 191 ## Context192 194-To handle Request and Reponse, you can use Context object:193+To handle Request and Reponse, you can use Context object.194 195 ### c.req196 197 ```js30 unmodified lines228 c.header('Content-Type', 'text/plain')229 c.status(201)230 231 return c.body('Thank you for comming')232+})233+```234 234- /*235- Same as:236- return new Response('Thank you for comming', {237- status: 201,238- statusText: 'Created',239- headers: {240- 'X-Message': 'Hello',241- 'Content-Type': 'text/plain',242- 'Content-Length: '22'243- }244- })245- */235+The Response is the same as below.236+237+```js238+new Response('Thank you for comming', {239+ status: 201,240+ statusText: 'Created',241+ headers: {242+ 'X-Message': 'Hello',243+ 'Content-Type': 'text/plain',244+ 'Content-Length': '22',245+ },246 })247 ```248 249 ### c.text()250 251-Render text as `Content-Type:text/plain`:251+Render texts as `Content-Type:text/plain`.252 253 ```js254 app.get('/say', (c) => {255 return c.text('Hello!')1 unmodified line257 ```258 259 ### c.json()260 261-Render JSON as `Content-Type:application/json`:261+Render JSON as `Content-Type:application/json`.262 263 ```js264 app.get('/api', (c) => {265 return c.json({ message: 'Hello!' })1 unmodified line267 ```268 269 ### c.html()270 271-Render HTML as `Content-Type:text/html`:271+Render HTML as `Content-Type:text/html`.272 273 ```js274 app.get('/', (c) => {275 return c.html('<h1>Hello! Hono!</h1>')1 unmodified line277 ```278 279 ### c.notFound()280 281-Return the default `404 Not Found` Response:281+Return the default `404 Not Found` Response.282 283 ```js284 app.get('/notfound', (c) => {285 return c.notFound()1 unmodified line287 ```288 289 ### c.redirect()290 291-Redirect, default status code is `302`:291+Redirect, default status code is `302`.292 293 ```js294 app.get('/redirect', (c) => c.redirect('/'))295 app.get('/redirect-permanently', (c) => c.redirect('/', 301))32 unmodified lines328 ```329 330 ## Not Found331 332-If you want, you can set the default `404 Not Found` Response:332+You can write the default `404 Not Found` Response.333 334 ```js335 app.notFound = (c) => {336 return c.text('This is default 404 Not Found', 404)1 unmodified line338 ```339 340 ## Error handling341 342-You can handle errors in your way:342+You can handle errors in your way.343 344 ```js345 app.onError = (err, c) => {346 return c.text(`This is error message: ${err.mssage}`, 500)1 unmodified line348 ```349 350 ## fire351 352-`app.fire()` do:352+`app.fire()` do this.353 354 ```js355 addEventListener('fetch', (event) => {356 event.respondWith(this.handleEvent(event))11 unmodified lines368 },369 }370 371 /*372-or just do this:372+or just do:373 export default app374 */375 ```376 4 unmodified lines381 Let's write your first code for Cloudflare Workers with Hono.382 383 ### 1. Install Wrangler384 385-Install Cloudflare Command Line "[Wrangler](https://github.com/cloudflare/wrangler)"385+Install Cloudflare Command Line "[Wrangler](https://github.com/cloudflare/wrangler)".386 387 ```sh388-npm i @cloudflare/wrangler -g388+$ npm i @cloudflare/wrangler -g389 ```390 391 ### 2. `npm init`392 393-Make npm skeleton directory.393+Make a npm skeleton directory.394 395 ```sh396 mkdir hono-example397 cd hono-example4 unmodified lines402 403 Init as a wrangler project.404 405 ```sh406-wrangler init406+$ wrangler init407 ```408 409 ### 4. `npm install hono`410 411-Install `hono` from npm registry.411+Install `hono` from the npm registry.412 413 ```sh414-npm i hono414+$ npm i hono415 ```416 417 ### 5. Write your app418 9 unmodified lines428 ```429 430 ### 6. Run431 432-Run the development server locally. Then, access like `http://127.0.0.1:8787/` in your Web browser.432+Run the development server locally. Then, access `http://127.0.0.1:8787/` in your Web browser.433 434 ```sh435-wrangler dev435+$ wrangler dev436 ```437 438 ### 7. Publish439 440 Deploy to Cloudflare. That's all!441 442 ```sh443-wrangler publish443+$ wrangler publish444 ```445 446+## Starter template447+448+You can start making your application of Cloudflare Workers with [the starter template](https://github.com/yusukebe/hono-minimal). It is a realy minimal using TypeScript, esbuild, and Miniflare.449+450+To generate a project skelton, run this command.451+452+```453+$ wrangler generate my-app https://github.com/yusukebe/hono-minimal454+```455+456 ## Related projects457 448-Implementation of the router is inspired by [goblin](https://github.com/bmf-san/goblin). API design is inspired by [express](https://github.com/expressjs/express) and [koa](https://github.com/koajs/koa). [itty-router](https://github.com/kwhitley/itty-router), [Sunder](https://github.com/SunderJS/sunder), and [worktop](https://github.com/lukeed/worktop) are the other routers or frameworks for Cloudflare Workers.458+Implementation of the original router `TrieRouter` is inspired by [goblin](https://github.com/bmf-san/goblin). `RegExpRouter` is inspired by [Router::Boom](https://github.com/tokuhirom/Router-Boom). API design is inspired by [express](https://github.com/expressjs/express) and [koa](https://github.com/koajs/koa). [itty-router](https://github.com/kwhitley/itty-router), [Sunder](https://github.com/SunderJS/sunder), and [worktop](https://github.com/lukeed/worktop) are the other routers or frameworks for Cloudflare Workers.459 460 - express <https://github.com/expressjs/express>461 - koa <https://github.com/koajs/koa>462 - itty-router <https://github.com/kwhitley/itty-router>463 - Sunder <https://github.com/SunderJS/sunder>464 - goblin <https://github.com/bmf-san/goblin>465 - worktop <https://github.com/lukeed/worktop>466+- Router::Boom <https://github.com/tokuhirom/Router-Boom>467 468 ## Contributing469 459-Contributions Welcome! You can contribute by the following way:470+Contributions Welcome! You can contribute by the following way.471 472 - Write or fix documents473 - Write code of middleware474 - Fix bugs475 - Refactor the code476 - etc.477 467-If you can, let's make Hono together!478+Let's make Hono together!479 480 ## Contributors481 482 Thanks to [all contributors](https://github.com/yusukebe/hono/graphs/contributors)!8 unmodified lines