[{"data":1,"prerenderedAt":872},["ShallowReactive",2],{"navigation":3,"-guide":184,"-guide-surround":868},[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},"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","/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},"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":862,"extension":863,"meta":864,"navigation":865,"path":6,"seo":866,"stem":7,"__hash__":867},"content/1.guide/0.index.md",{"type":187,"value":188,"toc":856,"icon":11},"minimark",[189,204,209,238,249,262,268,272,276,288,296,299,302,413,416,474,477,481,484,494,514,534,541,587,589,597,599,608,625,654,664,667,775,781,852],[190,191,192],"important",{},[193,194,195,196,203],"p",{},"\nYou are currently reading H3 v2 docs. See ",[197,198,202],"a",{"href":199,"rel":200},"https://v1.h3.dev/",[201],"nofollow","v1.h3.dev"," for legacy docs.",[205,206,208],"h2",{"id":207},"overview","Overview",[193,210,211,212,216,217,216,221,226,227,232,233,237],{},"⚡ 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,213,99],{"href":214,"rel":215},"https://developer.mozilla.org/en-US/docs/Web/API/Request",[201],", ",[197,218,104],{"href":219,"rel":220},"https://developer.mozilla.org/en-US/docs/Web/API/Response",[201],[197,222,225],{"href":223,"rel":224},"https://developer.mozilla.org/en-US/docs/Web/API/URL",[201],"URL",", and ",[197,228,231],{"href":229,"rel":230},"https://developer.mozilla.org/en-US/docs/Web/API/Headers",[201],"Headers",". You can integrate H3 with any compatible runtime or ",[197,234,236],{"href":235},"/guide/api/h3#h3mount","mount"," other web-compatible handlers to H3 with almost no added latency.",[193,239,240,241,244,245,248],{},"H3 is designed to be extendable and composable. Instead of providing one big core, you start with a lightweight ",[197,242,243],{"href":61},"H3 instance"," and then import built-in, tree-shakable ",[197,246,247],{"href":93},"utilities"," or bring your own for more functionality.\nComposable utilities has several advantages:",[250,251,252,256,259],"ul",{},[253,254,255],"li",{},"The server only includes used code and runs them exactly where is needed.",[253,257,258],{},"Application size can scale better. Usage of utilities is explicit and clean, with less global impact.",[253,260,261],{},"H3 is minimally opinionated and won't limit your choices.",[193,263,264,265,267],{},"All utilities, share an ",[197,266,65],{"href":66}," context.",[269,270],"read-more",{"title":271,"to":93},"built-in H3 utilities",[205,273,275],{"id":274},"quick-start","Quick Start",[277,278,279],"tip",{},[193,280,281,282,287],{},"\nYou try H3 online ",[197,283,286],{"href":284,"rel":285},"https://stackblitz.com/github/h3js/h3/tree/main/playground?file=server.mjs",[201],"on ⚡️ Stackblitz ",".",[193,289,290,291,295],{},"Install ",[292,293,294],"code",{},"h3"," as a dependency:",[297,298],"pm-install",{"name":294},[193,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","",[292,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",[193,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",[292,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",[292,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",[292,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",[193,475,476],{},"And tadaa! We have a web server running locally.",[294,478,480],{"id":479},"what-happened","What Happened?",[193,482,483],{},"Okay, let's now break down our hello world example.",[193,485,486,487,489,490,493],{},"We first created an ",[197,488,60],{"href":61}," app instance using ",[292,491,492],{},"new H3()",":",[303,495,497],{"className":305,"code":496,"language":308,"meta":309,"style":309},"const app = new H3();\n",[292,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",[193,515,516,518,519,216,522,525,526,529,530,287],{},[197,517,60],{"href":61}," is a tiny class capable of ",[197,520,521],{"href":24},"matching routes",[197,523,524],{"href":39},"generating responses"," and calling ",[197,527,528],{"href":29},"middleware"," and ",[197,531,533],{"href":532},"/guide/api/h3#global-hooks","global hooks",[193,535,536,537,540],{},"Then we add a route for handling HTTP GET requests to ",[292,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",[292,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",[269,588],{"title":23,"to":24},[193,590,591,592,596],{},"We simply returned an object. H3 automatically ",[197,593,595],{"href":594},"/guide/basics/response#response-types","converts"," values into web responses.",[269,598],{"title":38,"to":39},[193,600,601,602,604,605,607],{},"Finally, we use ",[292,603,403],{}," method to start the server listener. Using ",[292,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",[292,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},[277,626,627],{},[193,628,629,630,632,633,638,639,216,644,529,649,287],{},"\nThe ",[292,631,403],{}," method is powered by ",[197,634,637],{"href":635,"rel":636},"https://srvx.h3.dev/",[201],"💥 srvx",", a runtime-agnostic universal server listener based on web standards that works seamlessly with ",[197,640,643],{"href":641,"rel":642},"https://deno.com/",[201],"Deno",[197,645,648],{"href":646,"rel":647},"https://nodejs.org/",[201],"Node.js",[197,650,653],{"href":651,"rel":652},"https://bun.sh/",[201],"Bun",[193,655,656,657,663],{},"We also have ",[197,658,660],{"href":659},"/guide/api/h3#h3fetch",[292,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.",[269,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.request(\"/\");\nconsole.log(await response.text());\n",[292,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},"request",[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",[193,776,777,778,780],{},"You can directly import ",[292,779,294],{}," 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\";\n\nconst app = new H3().get(\"/\", () => \"⚡️ Tadaa!\");\n\nexport const fetch = app.fetch;\n",[292,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\"",[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":207,"depth":337,"text":208},{"id":274,"depth":337,"text":275,"children":860},[861],{"id":479,"depth":344,"text":480},"Get started with H3.","md",{"automd":340,"icon":11},{"icon":11},{"title":10,"description":862},"4ES3cy6mSQEg40mYOAmrL0m-kPzEWicHdvEqtWJvSNo",[869,870],null,{"title":18,"path":19,"stem":20,"description":871,"icon":21,"children":-1},"H3 dispatches incoming web requests to final web responses.",1768646385961]