Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Hono - Ultrafast web framework for Cloudflare W...

Yusuke Wada
November 26, 2022

Hono - Ultrafast web framework for Cloudflare Workers, Deno, Bun, and Node.js

Yusuke Wada 2022.11.26 JSConf JP

Yusuke Wada

November 26, 2022
Tweet

More Decks by Yusuke Wada

Other Decks in Programming

Transcript

  1. Yusuke Wada 2022.11.26 JSConf JP Hono Ultrafast web framework for

    Cloud fl are Workers, Deno, Bun, and Node.js
  2. Me • Yusuke Wada • Supervisor at TravelBook Inc. •

    Web developer, Web framework developer • https://yusukebe.com/ • https://github.com/yusukebe 2
  3. Today's topics • Core concepts of Hono 1. Multi-runtimes 2.

    Ultrafast 3. Middleware 4. Experience 3
  4. Who is using Hono • cdnjs API Server • Drivly

    - Commerce infrastructure for the automotive industry • Ultra - Zero-Legacy Deno/React Suspense SSR Framework • Deno cli/bench/http 7
  5. Hono works on... • Cloud fl are Workers / workerd

    • Vercel Edge Runtime • Fastly Compute@Edge • Deno • Bun • Node.js • and more... 11
  6. Thanks to Web standards • Zero-dependencies / No poly fi

    ll • Web-interoperable Runtimes will be powered by WinterCG 17
  7. Node.js • Fastify • Reqs/sec 63417.00 5358.22 67487.06 • Express

    • Reqs/sec 20709.94 1683.03 23045.34 • Hono with @honojs/node-server • Reqs/sec 32054.95 2642.04 35583.36 28
  8. Node.js - router 29 Decode URI, Handle Query strings Does

    not support regexp Does not support regexp
  9. 3+1 Routers 1. StaticRouter • Fastest, supports only static routes.

    2. RegExpRouter • Faster, supports almost routes. 3. TrieRouter • Slowest, supports all routes. 
 But it's faster than other routers in the world. 31
  10. RegExpRouter • Match the route with using one big Regex

    made before dispatch. • By @usualoma • https://speakerdeck.com/usualoma/ultrafast-js-router 36
  11. 37

  12. StaticRouter • Optimized for static routings • Does not support

    dynamic routings such as "path parameters" 38
  13. SmartRouter • The default router • Automatically picks the best

    router from the three routers. 40 • StaticRouter • RegExpRouter • TrieRouter
  14. Small core • hono.ts • context.ts • compose.ts • request.ts

    43 Basic app with Wrangler: Total Upload: 34.15 KiB / gzip: 8.26 KiB
  15. Three types of Middleware • Built-in Middleware - including the

    package • Custom Middleware - created by the users • Third-party Middleware - depends on external libraries 44
  16. Built-in Middleware • Basic Auth • Bearer Auth • Cache

    • Compress • CORS • Etag • html • JSX • JWT Auth • Logger • Pretty JSON • Serve Static • Validator 45
  17. Third-party Middleware 49 • GraphQL Server • Firebase Auth •

    Sentry • tRPC (?) ref: https://github.com/honojs/hono/issues/582
  18. Easy to write tests • With `jest-environment-mini fl are` •

    We can do test `Request` to `Response` 55
  19. With Cloudflare R2 65 • github.com/yusukebe/r2-image-worker • Store and Deliver

    images with R2 backend Cloud fl are Workers. ref: https://github.com/yusukebe/r2-image-worker
  20. Pico 75 Pico is ultra-tiny (about 1kB) web framework using

    URLPattern. Pico works on Cloud fl are Workers and Deno. Pico is compatible with Hono.