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

どこでも動くWebフレームワークをつくる

 どこでも動くWebフレームワークをつくる

YAPC::Kyoto 2023
2023-03-19 Yusuke Wada

Yusuke Wada

March 19, 2023
Tweet

More Decks by Yusuke Wada

Other Decks in Programming

Transcript

  1. .F • Yusuke Wada • Supervisor@TravelBook
 https://www.travelbook.co.jp • Creator of

    Bokete • YAPC::Asia 2012/2013 ϕεττʔΫ৆ड৆ • https://github.com/yusukebe • https://twitter.com/yusukebe 
  2. ͦΕͳΓʹ࢖ΘΕͯ·͢ • cdnjs - ϥΠϒϥϦͷCDN഑৴αʔϏεɺAPIͰ࢖ΘΕ͍ͯΔ • Poly fi ll.io -

    ϒϥ΢βͷUAΛΈͯPoly fi llΛฦ͢ • Ultra - Deno޲͚ͷReact SSRϑϨʔϜϫʔΫ • Driv.ly - ंͷΦϯϥΠϯചങͷͨΊͷAPIΛఏڙ • repeat.dev - webhook΍scheduleλεΫͳͲΛૉૣͭ͘͘ΕΔ • Convex - σʔλϕʔεαʔϏεɺHonoͷར༻Λਪ঑͍ͯ͠Δ • Cloud fl are D1 example - Cloud fl areެࣜͷϒϩά • subtats - ΞΧ΢ϯτͷϑΥϩʔϫʔ͕Կਓ͍Δ͔Θ͔ΔOSS 
  3. )POPͷͭͷಛ௃ • Ultrafast
 The routers are really fast and smart.

    Not using linear loops. Fast. • Multi-runtime
 Works on Cloud fl are Workers, Fastly Compute@Edge, Deno, Bun, Lagon, or Node.js. The same code runs on all platforms. • Batteries Included
 Hono has built-in middleware, custom middleware, and third-party middleware. Batteries included. • Delightful DX
 First-class TypeScript support. Now, we've got "Types". • Small
 About 20kB. Zero-dependencies. Using only Web Standard API.  3FH&YQ3PVUFS +BWB4DSJQUքͰ࠷଎ͷϧʔλʔ CZ!VTVBMPNB ࠓճ͸͜͜ʹয఺Λ͋ͯ·͢
  4. 8FC4UBOEBSEͷ͓͔͛ • Fetch APIͰ࢖༻͞ΕΔRequest/ResponseɺετϦʔϜɺ҉߸ԽͳͲ • Webϒϥ΢βͷAPIΛαʔόʔ(Ϩε)؀ڥͰ࢖͑ΔΑ͏ʹ͢Δ • WinterCGͰٞ࿦͞Ε͍ͯΔ • Web-interoperable

    Runtimes Community Group • W3CͷίϛϡχςΟʔάϧʔϓ • Cloud fl are / Deno / Vercel / Shopify / Netlify / Alibaba etc.  ʮ֎෦ϥΠϒϥϦʹґଘͤͣɺ8FC4UBOEBSEͷ"1*ͷΈΛ࢖༻͍ͯ͠Δʯ 8FC4UBOEBSEͱ͸ʁ
  5. w 3FRVFTU w 3FTQPOTF w 63- w 63-1BUUFSO w 63-4FBSDI1BSBNT

    w $SZQUP w 3FBEBCMF4USFBN w 8SJUBCMF4USFBN w 5FYU&ODPEFS w 5FYU%FDPEFS 8FC4UBOEBSEͷ"1* ͳͲ 
  6. )POP಺෦Ͱ΍ͬͯΔ͜ͱ 1. dispatch(request:Request) 2. [handlers, params] = match(method, path) 3.

    context = new Context(request, params) 4. composed = compose(handlers) 5. response = composed(context) 6. return response:Response 
  7. خ͔ͬͨ͠ॠؒ $MPVE fl BSF8PSLFSTͷ$-*8SBOHMFSͷ ݩ ϝΠϯϝϯςφ !UISFFQPJOUPOF4VOJM͕πΠʔτͯ͘͠Εͨʂ  This looks

    like a pretty neat batteries-included framework for Cloudflare Workers! Nice work @yusukebe
  8. %FOPʹରԠͤ͞Δ w EFOPJGZ w AEFOPJGZAίϚϯυͰ%FOP༻ͷίʔυΛग़ྗͯ͘͠ΕΔ w AUTA֦ுࢠΛ͚ͭͯ͘ΕΔɺ1PMZ fi MMɺϞδϡʔϧͷϦϓϨΠε w

    EFOPMBOEYͰͷެ։ w AEFOPJGZAͰग़ྗͨ͠AEFOP@EJTUAΛࢦఆ͢Ε͹ެ։Ͱ͖ͨ ͨͩ͠Deno v1.28͔Β`npm: ` speci fi ers͕ಋೖ͞Εͨ `npm:hono` ͰimportͰ͖Δ
  9. $MPVEGMBSF8PSLFSTͱશ͘ಉ͡ίʔυ͕ಈ͍ͨ • Web StandardΛ࠾༻ • `export { fetch }` ΋ಉ͡

    #VO͕ެ։͞Εͨ࣌ʹ͸΋͏͢ͰʹରԠͰ͖ͯͨ • Bunjs support · Issue #344 · honojs/honoʯ
 https://github.com/honojs/hono/issues/344