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