Slide 1

Slide 1 text

Yusuke Wada 2022.11.26 JSConf JP Hono Ultrafast web framework for Cloud fl are Workers, Deno, Bun, and Node.js

Slide 2

Slide 2 text

Me • Yusuke Wada • Supervisor at TravelBook Inc. • Web developer, Web framework developer • https://yusukebe.com/ • https://github.com/yusukebe 2

Slide 3

Slide 3 text

Today's topics • Core concepts of Hono 1. Multi-runtimes 2. Ultrafast 3. Middleware 4. Experience 3

Slide 4

Slide 4 text

Hono in 1min. 4

Slide 5

Slide 5 text

Initial Commit • 2021-12-15 5

Slide 6

Slide 6 text

Star History 6

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

Workers Launchpad 8 ref: https://blog.cloud fl are.com/launchpad-fall-22/

Slide 9

Slide 9 text

Deno benchmarks 9 https://deno.land/benchmarks

Slide 10

Slide 10 text

Concept 1 Multi-runtimes 10

Slide 11

Slide 11 text

Hono works on... • Cloud fl are Workers / workerd • Vercel Edge Runtime • Fastly Compute@Edge • Deno • Bun • Node.js • and more... 11

Slide 12

Slide 12 text

The same code runs on all platforms 12

Slide 13

Slide 13 text

Cloudflare Workers and Bun

Slide 14

Slide 14 text

Fastly Compute@Edge and Vercel Edge Runtime

Slide 15

Slide 15 text

Deno

Slide 16

Slide 16 text

Node.js

Slide 17

Slide 17 text

Thanks to Web standards • Zero-dependencies / No poly fi ll • Web-interoperable Runtimes will be powered by WinterCG 17

Slide 18

Slide 18 text

Cloudflare Workers 18 ref: https://developers.cloud fl are.com/workers/runtime-apis/

Slide 19

Slide 19 text

Deno 19 ref: https://deno.land/[email protected]/runtime/web_platform_apis

Slide 20

Slide 20 text

Bun 20 ref: https://github.com/oven-sh/bun#Reference

Slide 21

Slide 21 text

Node.js 21 ref: https://github.com/honojs/node-server • Using `@remix-run/web-fetch`

Slide 22

Slide 22 text

context.ts 22 Discussion in WinterCG => https://github.com/wintercg/runtime-keys/pull/2

Slide 23

Slide 23 text

Great 👍 23

Slide 24

Slide 24 text

Concept 2 Ultrafast 24

Slide 25

Slide 25 text

Cloudflare Workers 25 ref: https://github.com/honojs/hono/tree/main/benchmarks/handle-event

Slide 26

Slide 26 text

Deno 26 ref: https://github.com/denosaurs/bench

Slide 27

Slide 27 text

Bun 27 ref: https://github.com/SaltyAom/bun-http-framework-benchmark

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

Node.js - router 29 Decode URI, Handle Query strings Does not support regexp Does not support regexp

Slide 30

Slide 30 text

Why so fast? 30

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

"Linear" router 32

Slide 33

Slide 33 text

ref: https://github.com/yusukebe/pico

Slide 34

Slide 34 text

TrieRouter • Using Trie Tree structure • Support all patterns 34

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

RegExpRouter • Match the route with using one big Regex made before dispatch. • By @usualoma • https://speakerdeck.com/usualoma/ultrafast-js-router 36

Slide 37

Slide 37 text

37

Slide 38

Slide 38 text

StaticRouter • Optimized for static routings • Does not support dynamic routings such as "path parameters" 38

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

SmartRouter • The default router • Automatically picks the best router from the three routers. 40 • StaticRouter • RegExpRouter • TrieRouter

Slide 41

Slide 41 text

Great 👍 41

Slide 42

Slide 42 text

Concept 3 Middleware 42

Slide 43

Slide 43 text

Small core • hono.ts • context.ts • compose.ts • request.ts 43 Basic app with Wrangler: Total Upload: 34.15 KiB / gzip: 8.26 KiB

Slide 44

Slide 44 text

Three types of Middleware • Built-in Middleware - including the package • Custom Middleware - created by the users • Third-party Middleware - depends on external libraries 44

Slide 45

Slide 45 text

Built-in Middleware • Basic Auth • Bearer Auth • Cache • Compress • CORS • Etag • html • JSX • JWT Auth • Logger • Pretty JSON • Serve Static • Validator 45

Slide 46

Slide 46 text

JSX Middleware 46

Slide 47

Slide 47 text

Validator Middleware 47

Slide 48

Slide 48 text

Custom Middleware 48

Slide 49

Slide 49 text

Third-party Middleware 49 • GraphQL Server • Firebase Auth • Sentry • tRPC (?) ref: https://github.com/honojs/hono/issues/582

Slide 50

Slide 50 text

Great 👍 50

Slide 51

Slide 51 text

Concept 4 Experience 51

Slide 52

Slide 52 text

TypeScript • Wrangler, Deno, and Bun fi rst-class support TypeScript. 52

Slide 53

Slide 53 text

Path parameters 53

Slide 54

Slide 54 text

Validator Middleware 54

Slide 55

Slide 55 text

Easy to write tests • With `jest-environment-mini fl are` • We can do test `Request` to `Response` 55

Slide 56

Slide 56 text

Great 👍 56

Slide 57

Slide 57 text

Example: Blog 57

Slide 58

Slide 58 text

import 58

Slide 59

Slide 59 text

Model 59

Slide 60

Slide 60 text

Logic 60

Slide 61

Slide 61 text

JSX 61

Slide 62

Slide 62 text

GET / 62

Slide 63

Slide 63 text

POST /post 63

Slide 64

Slide 64 text

Use cases in the real world 64

Slide 65

Slide 65 text

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

Slide 66

Slide 66 text

With Cloudflare D1 66 ref: https://blog.cloud fl are.com/making-static-sites-dynamic-with-cloud fl are-d1/

Slide 67

Slide 67 text

Cache control 67 ref: https://yusukebe.com/posts/2022/wsh/

Slide 68

Slide 68 text

Express alternative on Bun 68

Slide 69

Slide 69 text

Feature plans 69

Slide 70

Slide 70 text

Ecosystem • For Third-party Middleware • monorepo • API specs as Types • tRPC like, but integrated 70

Slide 71

Slide 71 text

API specs as Types 71 ref: https://github.com/honojs/hono/issues/582

Slide 72

Slide 72 text

And... 72

Slide 73

Slide 73 text

Going to Standard web framework for Web standards 73

Slide 74

Slide 74 text

One more thing 74

Slide 75

Slide 75 text

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.

Slide 76

Slide 76 text

Love 76

Slide 77

Slide 77 text

Thanks • Thanks to all contributors, all supporters, and all users!! 77

Slide 78

Slide 78 text

Try Hono! 78 https://honojs.dev