[{"data":1,"prerenderedAt":872},["ShallowReactive",2],{"navigation":3,"-guide":179,"-guide-surround":868},[4,86,128,156,163],{"title":5,"path":6,"stem":7,"children":8,"icon":85},"Guide","/guide","1.guide/0.index",[9,12,48,64],{"title":10,"path":6,"stem":7,"icon":11},"Getting Started","pixel:play",{"title":5,"icon":13,"path":14,"stem":15,"children":16,"page":47},"ph:book-open-duotone","/guide/basics","1.guide/1.basics",[17,22,27,32,37,42],{"title":18,"path":19,"stem":20,"icon":21},"Request Lifecycle","/guide/basics/lifecycle","1.guide/1.basics/1.lifecycle","icon-park-outline:handle-round",{"title":23,"path":24,"stem":25,"icon":26},"Routing","/guide/basics/routing","1.guide/1.basics/2.routing","solar:routing-bold",{"title":28,"path":29,"stem":30,"icon":31},"Middleware","/guide/basics/middleware","1.guide/1.basics/3.middleware","mdi:middleware-outline",{"title":33,"path":34,"stem":35,"icon":36},"Event Handlers","/guide/basics/handler","1.guide/1.basics/4.handler","mdi:function",{"title":38,"path":39,"stem":40,"icon":41},"Sending Response","/guide/basics/response","1.guide/1.basics/5.response","tabler:json",{"title":43,"path":44,"stem":45,"icon":46},"Error Handling","/guide/basics/error","1.guide/1.basics/6.error","tabler:error-404",false,{"title":49,"icon":50,"path":51,"stem":52,"children":53,"page":47},"API","material-symbols-light:api-rounded","/guide/api","1.guide/900.api",[54,59],{"title":55,"path":56,"stem":57,"icon":58},"H3","/guide/api/h3","1.guide/900.api/1.h3","material-symbols:bolt-rounded",{"title":60,"path":61,"stem":62,"icon":63},"H3Event","/guide/api/h3event","1.guide/900.api/2.h3event","material-symbols:data-object-rounded",{"title":65,"icon":66,"path":67,"stem":68,"children":69,"page":47},"Advanced","hugeicons:more-01","/guide/advanced","1.guide/901.advanced",[70,75,80],{"title":71,"path":72,"stem":73,"icon":74},"Plugins","/guide/advanced/plugins","1.guide/901.advanced/1.plugins","clarity:plugin-line",{"title":76,"path":77,"stem":78,"icon":79},"WebSockets","/guide/advanced/websocket","1.guide/901.advanced/2.websocket","hugeicons:live-streaming-02",{"title":81,"path":82,"stem":83,"icon":84},"Nightly Builds","/guide/advanced/nightly","1.guide/901.advanced/9.nightly","game-icons:barn-owl","i-ph:book-open-duotone",{"title":87,"path":88,"stem":89,"children":90,"icon":92},"H3 Utils","/utils","2.utils/0.index",[91,93,98,103,108,113,118,123],{"title":87,"path":88,"stem":89,"icon":92},"ph:function-bold",{"title":94,"path":95,"stem":96,"icon":97},"Request","/utils/request","2.utils/1.request","material-symbols-light:input",{"title":99,"path":100,"stem":101,"icon":102},"Response","/utils/response","2.utils/2.response","material-symbols-light:output",{"title":104,"path":105,"stem":106,"icon":107},"Cookie","/utils/cookie","2.utils/3.cookie","material-symbols:cookie-outline",{"title":109,"path":110,"stem":111,"icon":112},"Security","/utils/security","2.utils/4.security","wpf:key-security",{"title":114,"path":115,"stem":116,"icon":117},"Proxy","/utils/proxy","2.utils/5.proxy","arcticons:super-proxy",{"title":119,"path":120,"stem":121,"icon":122},"More utils","/utils/more","2.utils/9.more","mingcute:plus-line",{"title":124,"path":125,"stem":126,"icon":127},"Community","/utils/community","2.utils/99.community","lets-icons:external",{"title":129,"path":130,"stem":131,"children":132,"icon":134},"Examples","/examples","4.examples/0.index",[133,135,140,144,148,152],{"title":129,"path":130,"stem":131,"icon":134},"ph:code",{"title":136,"path":137,"stem":138,"icon":139},"Cookies","/examples/handle-cookie","4.examples/handle-cookie","ph:arrow-right",{"title":141,"path":142,"stem":143,"icon":139},"Sessions","/examples/handle-session","4.examples/handle-session",{"title":145,"path":146,"stem":147,"icon":139},"Static Assets","/examples/serve-static-assets","4.examples/serve-static-assets",{"title":149,"path":150,"stem":151,"icon":139},"Stream Response","/examples/stream-response","4.examples/stream-response",{"title":153,"path":154,"stem":155,"icon":139},"Validate Data","/examples/validate-data","4.examples/validate-data",{"title":157,"path":158,"stem":159,"children":160,"icon":162},"Migration guide for v1 to v2","/migration","5.migration/0.index",[161],{"title":157,"path":158,"stem":159,"icon":162},"icons8:up-round",{"title":164,"path":165,"stem":166,"children":167,"page":-1},"Blog","/blog","99.blog",[168,171,175],{"title":164,"path":165,"stem":169,"icon":170},"99.blog/index","i-lucide-file-text",{"title":172,"path":173,"stem":174,"icon":170},"H3 1.8 - Towards the Edge of the Web","/blog/v1.8","99.blog/1.v1.8",{"title":176,"path":177,"stem":178,"icon":170},"H3 v2 beta","/blog/v2-beta","99.blog/2.v2-beta",{"id":180,"title":10,"body":181,"description":862,"extension":863,"meta":864,"navigation":865,"path":6,"seo":866,"stem":7,"__hash__":867},"content/1.guide/0.index.md",{"type":182,"value":183,"toc":856,"icon":11},"minimark",[184,203,208,237,248,261,267,271,275,287,295,299,302,413,416,474,477,481,484,494,514,534,541,587,589,597,599,608,625,654,664,667,775,781,852],[185,186,187],"important",{},[188,189,190,191,195,196,202],"p",{},"\nYou are currently reading H3 version 2 (",[192,193,194],"a",{"href":177},"beta",") documentation. See ",[192,197,201],{"href":198,"rel":199},"https://v1.h3.dev/",[200],"nofollow","v1.h3.dev"," for older docs.",[204,205,207],"h2",{"id":206},"overview","Overview",[188,209,210,211,215,216,215,220,225,226,231,232,236],{},"⚡ H3 (short for H(TTP), pronounced as /eɪtʃθriː/, like h-3) is a lightweight, fast, and composable server framework for modern JavaScript runtimes. It is based on web standard primitives such as ",[192,212,94],{"href":213,"rel":214},"https://developer.mozilla.org/en-US/docs/Web/API/Request",[200],", ",[192,217,99],{"href":218,"rel":219},"https://developer.mozilla.org/en-US/docs/Web/API/Response",[200],[192,221,224],{"href":222,"rel":223},"https://developer.mozilla.org/en-US/docs/Web/API/URL",[200],"URL",", and ",[192,227,230],{"href":228,"rel":229},"https://developer.mozilla.org/en-US/docs/Web/API/Headers",[200],"Headers",". You can integrate H3 with any compatible runtime or ",[192,233,235],{"href":234},"/guide/api/h3#h3mount","mount"," other web-compatible handlers to H3 with almost no added latency.",[188,238,239,240,243,244,247],{},"H3 is designed to be extendable and composable. Instead of providing one big core, you start with a lightweight ",[192,241,242],{"href":56},"H3 instance"," and then import built-in, tree-shakable ",[192,245,246],{"href":88},"utilities"," or bring your own for more functionality.\nComposable utilities has several advantages:",[249,250,251,255,258],"ul",{},[252,253,254],"li",{},"The server only includes used code and runs them exactly where is needed.",[252,256,257],{},"Application size can scale better. Usage of utilities is explicit and clean, with less global impact.",[252,259,260],{},"H3 is minimally opinionated and won't limit your choices.",[188,262,263,264,266],{},"All utilities, share an ",[192,265,60],{"href":61}," context.",[268,269],"read-more",{"title":270,"to":88},"built-in H3 utilities",[204,272,274],{"id":273},"quick-start","Quick Start",[276,277,278],"tip",{},[188,279,280,281,286],{},"\nYou try H3 online ",[192,282,285],{"href":283,"rel":284},"https://stackblitz.com/github/h3js/h3/tree/main/playground?file=server.mjs",[200],"on ⚡️ Stackblitz ",".",[188,288,289,290,294],{},"Install ",[291,292,293],"code",{},"h3"," as a dependency:",[296,297],"pm-install",{"name":298},"h3@beta",[188,300,301],{},"Create a new file for server entry:",[303,304,310],"pre",{"className":305,"code":306,"filename":307,"language":308,"meta":309,"style":309},"language-ts shiki shiki-themes github-light github-dark github-dark","import { H3, serve } from \"h3\";\n\nconst app = new H3().get(\"/\", (event) => \"⚡️ Tadaa!\");\n\nserve(app, { port: 3000 });\n","server.mjs","ts","",[291,311,312,335,342,393,398],{"__ignoreMap":309},[313,314,317,321,325,328,332],"span",{"class":315,"line":316},"line",1,[313,318,320],{"class":319},"so5gQ","import",[313,322,324],{"class":323},"slsVL"," { H3, serve } ",[313,326,327],{"class":319},"from",[313,329,331],{"class":330},"sfrk1"," \"h3\"",[313,333,334],{"class":323},";\n",[313,336,338],{"class":315,"line":337},2,[313,339,341],{"emptyLinePlaceholder":340},true,"\n",[313,343,345,348,352,355,358,362,365,368,371,374,377,381,384,387,390],{"class":315,"line":344},3,[313,346,347],{"class":319},"const",[313,349,351],{"class":350},"suiK_"," app",[313,353,354],{"class":319}," =",[313,356,357],{"class":319}," new",[313,359,361],{"class":360},"shcOC"," H3",[313,363,364],{"class":323},"().",[313,366,367],{"class":360},"get",[313,369,370],{"class":323},"(",[313,372,373],{"class":330},"\"/\"",[313,375,376],{"class":323},", (",[313,378,380],{"class":379},"sQHwn","event",[313,382,383],{"class":323},") ",[313,385,386],{"class":319},"=>",[313,388,389],{"class":330}," \"⚡️ Tadaa!\"",[313,391,392],{"class":323},");\n",[313,394,396],{"class":315,"line":395},4,[313,397,341],{"emptyLinePlaceholder":340},[313,399,401,404,407,410],{"class":315,"line":400},5,[313,402,403],{"class":360},"serve",[313,405,406],{"class":323},"(app, { port: ",[313,408,409],{"class":350},"3000",[313,411,412],{"class":323}," });\n",[188,414,415],{},"Then, run the server using your favorite runtime:",[417,418,419,437,457],"code-group",{},[303,420,425],{"className":421,"code":422,"filename":423,"language":424,"meta":309,"style":309},"language-bash shiki shiki-themes github-light github-dark github-dark","node --watch ./server.mjs\n","node","bash",[291,426,427],{"__ignoreMap":309},[313,428,429,431,434],{"class":315,"line":316},[313,430,423],{"class":360},[313,432,433],{"class":350}," --watch",[313,435,436],{"class":330}," ./server.mjs\n",[303,438,441],{"className":421,"code":439,"filename":440,"language":424,"meta":309,"style":309},"deno run -A --watch ./server.mjs\n","deno",[291,442,443],{"__ignoreMap":309},[313,444,445,447,450,453,455],{"class":315,"line":316},[313,446,440],{"class":360},[313,448,449],{"class":330}," run",[313,451,452],{"class":350}," -A",[313,454,433],{"class":350},[313,456,436],{"class":330},[303,458,461],{"className":421,"code":459,"filename":460,"language":424,"meta":309,"style":309},"bun run --watch server.mjs\n","bun",[291,462,463],{"__ignoreMap":309},[313,464,465,467,469,471],{"class":315,"line":316},[313,466,460],{"class":360},[313,468,449],{"class":330},[313,470,433],{"class":350},[313,472,473],{"class":330}," server.mjs\n",[188,475,476],{},"And tadaa! We have a web server running locally.",[293,478,480],{"id":479},"what-happened","What Happened?",[188,482,483],{},"Okay, let's now break down our hello world example.",[188,485,486,487,489,490,493],{},"We first created an ",[192,488,55],{"href":56}," app instance using ",[291,491,492],{},"new H3()",":",[303,495,497],{"className":305,"code":496,"language":308,"meta":309,"style":309},"const app = new H3();\n",[291,498,499],{"__ignoreMap":309},[313,500,501,503,505,507,509,511],{"class":315,"line":316},[313,502,347],{"class":319},[313,504,351],{"class":350},[313,506,354],{"class":319},[313,508,357],{"class":319},[313,510,361],{"class":360},[313,512,513],{"class":323},"();\n",[188,515,516,518,519,215,522,525,526,529,530,286],{},[192,517,55],{"href":56}," is a tiny class capable of ",[192,520,521],{"href":24},"matching routes",[192,523,524],{"href":39},"generating responses"," and calling ",[192,527,528],{"href":29},"middleware"," and ",[192,531,533],{"href":532},"/guide/api/h3#global-hooks","global hooks",[188,535,536,537,540],{},"Then we add a route for handling HTTP GET requests to ",[291,538,539],{},"/"," path.",[303,542,544],{"className":305,"code":543,"language":308,"meta":309,"style":309},"app.get(\"/\", (event) => {\n  return { message: \"⚡️ Tadaa!\" };\n});\n",[291,545,546,568,582],{"__ignoreMap":309},[313,547,548,551,553,555,557,559,561,563,565],{"class":315,"line":316},[313,549,550],{"class":323},"app.",[313,552,367],{"class":360},[313,554,370],{"class":323},[313,556,373],{"class":330},[313,558,376],{"class":323},[313,560,380],{"class":379},[313,562,383],{"class":323},[313,564,386],{"class":319},[313,566,567],{"class":323}," {\n",[313,569,570,573,576,579],{"class":315,"line":337},[313,571,572],{"class":319},"  return",[313,574,575],{"class":323}," { message: ",[313,577,578],{"class":330},"\"⚡️ Tadaa!\"",[313,580,581],{"class":323}," };\n",[313,583,584],{"class":315,"line":344},[313,585,586],{"class":323},"});\n",[268,588],{"title":23,"to":24},[188,590,591,592,596],{},"We simply returned an object. H3 automatically ",[192,593,595],{"href":594},"/guide/basics/response#response-types","converts"," values into web responses.",[268,598],{"title":38,"to":39},[188,600,601,602,604,605,607],{},"Finally, we use ",[291,603,403],{}," method to start the server listener. Using ",[291,606,403],{}," method you can easily start an H3 server in various runtimes.",[303,609,613],{"className":610,"code":611,"language":612,"meta":309,"style":309},"language-js shiki shiki-themes github-light github-dark github-dark","serve(app, { port: 3000 });\n","js",[291,614,615],{"__ignoreMap":309},[313,616,617,619,621,623],{"class":315,"line":316},[313,618,403],{"class":360},[313,620,406],{"class":323},[313,622,409],{"class":350},[313,624,412],{"class":323},[276,626,627],{},[188,628,629,630,632,633,638,639,215,644,529,649,286],{},"\nThe ",[291,631,403],{}," method is powered by ",[192,634,637],{"href":635,"rel":636},"https://srvx.h3.dev/",[200],"💥 Srvx",", a runtime-agnostic universal server listener based on web standards that works seamlessly with ",[192,640,643],{"href":641,"rel":642},"https://deno.com/",[200],"Deno",[192,645,648],{"href":646,"rel":647},"https://nodejs.org/",[200],"Node.js",[192,650,653],{"href":651,"rel":652},"https://bun.sh/",[200],"Bun",[188,655,656,657,663],{},"We also have ",[192,658,660],{"href":659},"/guide/api/h3#h3fetch",[291,661,662],{},"app.fetch"," which can be directly used to run H3 apps in any web-compatible runtime or even directly called for testing purposes.",[268,665],{"title":666,"to":659},"H3.fetch",[303,668,670],{"className":610,"code":669,"language":612,"meta":309,"style":309},"import { H3, serve } from \"h3\";\n\nconst app = new H3().get(\"/\", () => \"⚡️ Tadaa!\");\n\n// Test without listening\nconst response = await app.fetch(\"/\");\nconsole.log(await response.text());\n",[291,671,672,684,688,717,721,727,752],{"__ignoreMap":309},[313,673,674,676,678,680,682],{"class":315,"line":316},[313,675,320],{"class":319},[313,677,324],{"class":323},[313,679,327],{"class":319},[313,681,331],{"class":330},[313,683,334],{"class":323},[313,685,686],{"class":315,"line":337},[313,687,341],{"emptyLinePlaceholder":340},[313,689,690,692,694,696,698,700,702,704,706,708,711,713,715],{"class":315,"line":344},[313,691,347],{"class":319},[313,693,351],{"class":350},[313,695,354],{"class":319},[313,697,357],{"class":319},[313,699,361],{"class":360},[313,701,364],{"class":323},[313,703,367],{"class":360},[313,705,370],{"class":323},[313,707,373],{"class":330},[313,709,710],{"class":323},", () ",[313,712,386],{"class":319},[313,714,389],{"class":330},[313,716,392],{"class":323},[313,718,719],{"class":315,"line":395},[313,720,341],{"emptyLinePlaceholder":340},[313,722,723],{"class":315,"line":400},[313,724,726],{"class":725},"sCsY4","// Test without listening\n",[313,728,730,732,735,737,740,743,746,748,750],{"class":315,"line":729},6,[313,731,347],{"class":319},[313,733,734],{"class":350}," response",[313,736,354],{"class":319},[313,738,739],{"class":319}," await",[313,741,742],{"class":323}," app.",[313,744,745],{"class":360},"fetch",[313,747,370],{"class":323},[313,749,373],{"class":330},[313,751,392],{"class":323},[313,753,755,758,761,763,766,769,772],{"class":315,"line":754},7,[313,756,757],{"class":323},"console.",[313,759,760],{"class":360},"log",[313,762,370],{"class":323},[313,764,765],{"class":319},"await",[313,767,768],{"class":323}," response.",[313,770,771],{"class":360},"text",[313,773,774],{"class":323},"());\n",[188,776,777,778,780],{},"You can directly import ",[291,779,293],{}," library from CDN alternatively. This method can be used for Bun, Deno and other runtimes such as Cloudflare Workers.",[303,782,784],{"className":610,"code":783,"language":612,"meta":309,"style":309},"import { H3 } from \"https://esm.sh/h3@beta\";\n\nconst app = new H3().get(\"/\", () => \"⚡️ Tadaa!\");\n\nexport const fetch = app.fetch;\n",[291,785,786,800,804,832,836],{"__ignoreMap":309},[313,787,788,790,793,795,798],{"class":315,"line":316},[313,789,320],{"class":319},[313,791,792],{"class":323}," { H3 } ",[313,794,327],{"class":319},[313,796,797],{"class":330}," \"https://esm.sh/h3@beta\"",[313,799,334],{"class":323},[313,801,802],{"class":315,"line":337},[313,803,341],{"emptyLinePlaceholder":340},[313,805,806,808,810,812,814,816,818,820,822,824,826,828,830],{"class":315,"line":344},[313,807,347],{"class":319},[313,809,351],{"class":350},[313,811,354],{"class":319},[313,813,357],{"class":319},[313,815,361],{"class":360},[313,817,364],{"class":323},[313,819,367],{"class":360},[313,821,370],{"class":323},[313,823,373],{"class":330},[313,825,710],{"class":323},[313,827,386],{"class":319},[313,829,389],{"class":330},[313,831,392],{"class":323},[313,833,834],{"class":315,"line":395},[313,835,341],{"emptyLinePlaceholder":340},[313,837,838,841,844,847,849],{"class":315,"line":400},[313,839,840],{"class":319},"export",[313,842,843],{"class":319}," const",[313,845,846],{"class":350}," fetch",[313,848,354],{"class":319},[313,850,851],{"class":323}," app.fetch;\n",[853,854,855],"style",{},"html pre.shiki code .so5gQ, html code.shiki .so5gQ{--shiki-light:#D73A49;--shiki-default:#F97583;--shiki-dark:#F97583}html pre.shiki code .slsVL, html code.shiki .slsVL{--shiki-light:#24292E;--shiki-default:#E1E4E8;--shiki-dark:#E1E4E8}html pre.shiki code .sfrk1, html code.shiki .sfrk1{--shiki-light:#032F62;--shiki-default:#9ECBFF;--shiki-dark:#9ECBFF}html pre.shiki code .suiK_, html code.shiki .suiK_{--shiki-light:#005CC5;--shiki-default:#79B8FF;--shiki-dark:#79B8FF}html pre.shiki code .shcOC, html code.shiki .shcOC{--shiki-light:#6F42C1;--shiki-default:#B392F0;--shiki-dark:#B392F0}html pre.shiki code .sQHwn, html code.shiki .sQHwn{--shiki-light:#E36209;--shiki-default:#FFAB70;--shiki-dark:#FFAB70}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sCsY4, html code.shiki .sCsY4{--shiki-light:#6A737D;--shiki-default:#6A737D;--shiki-dark:#6A737D}",{"title":309,"searchDepth":337,"depth":337,"links":857},[858,859],{"id":206,"depth":337,"text":207},{"id":273,"depth":337,"text":274,"children":860},[861],{"id":479,"depth":344,"text":480},"Get started with H3.","md",{"automd":340,"icon":11},{"icon":11},{"title":10,"description":862},"01vc0m0cchX0gwUQtGQ-3mbzvJymuHNMfv-P6PZd8BE",[869,870],null,{"title":18,"path":19,"stem":20,"description":871,"icon":21,"children":-1},"H3 dispatches incoming web requests to final web responses.",1750975919795]