[{"data":1,"prerenderedAt":677,"buildId":678},["ShallowReactive",2],{"page:\u002Fextensions\u002Fkubb-labs\u002Fplugin-fetch":3},{"id":4,"frontmatter":5,"title":6,"heading":6,"body":7,"path":676,"source":4},"extensions\u002Fkubb-labs\u002Fplugin-fetch\u002Findex.md",{},"Fetch",{"type":8,"value":9,"toc":667},"minimark",[10,14,48,53,153,183,187,223,227,315,327,331,639],[11,12,13],"p",{},"Generates one typed async function per OpenAPI operation that sends the request with the native Fetch API and returns a result keyed by status code.",[11,15,16,17,21,22,21,25,21,28,31,32,35,36,39,40,43,44,47],{},"Each function takes grouped ",[18,19,20],"code",{},"path",", ",[18,23,24],{},"query",[18,26,27],{},"headers",[18,29,30],{},"cookies",", and ",[18,33,34],{},"body"," options. The query plugins and ",[18,37,38],{},"@kubb\u002Fplugin-mcp"," call these functions. The runtime is copied into ",[18,41,42],{},".kubb\u002F",", so the generated code needs only the global ",[18,45,46],{},"fetch",".",[49,50,52],"h2",{"id":51},"installation","Installation",[54,55,57,80,100,118,136],"code-group",{"sync":56},"install",[58,59,64],"pre",{"language":60,"filename":61,"code":62,"class":63},"shell","kubb","kubb add plugin-fetch","highlights",[18,65,67],{"class":66},"language-shell",[68,69,72,76],"span",{"class":70,"style":71},"line","display: inline",[68,73,75],{"style":74},"color:#6f42c1;--hls-dark:#b392f0","kubb ",[68,77,79],{"style":78},"color:#24292e;--hls-dark:#e1e4e8","add plugin-fetch",[58,81,84],{"language":60,"filename":82,"code":83,"class":63},"bun","bun add -d @kubb\u002Fplugin-fetch",[18,85,86],{"class":66},[68,87,88,91,94,97],{"class":70,"style":71},[68,89,90],{"style":74},"bun ",[68,92,93],{"style":78},"add -d ",[68,95,96],{"style":78},"@",[68,98,99],{"style":78},"kubb\u002Fplugin-fetch",[58,101,104],{"language":60,"filename":102,"code":103,"class":63},"pnpm","pnpm add -D @kubb\u002Fplugin-fetch",[18,105,106],{"class":66},[68,107,108,111,114,116],{"class":70,"style":71},[68,109,110],{"style":74},"pnpm ",[68,112,113],{"style":78},"add -D ",[68,115,96],{"style":78},[68,117,99],{"style":78},[58,119,122],{"language":60,"filename":120,"code":121,"class":63},"npm","npm install --save-dev @kubb\u002Fplugin-fetch",[18,123,124],{"class":66},[68,125,126,129,132,134],{"class":70,"style":71},[68,127,128],{"style":74},"npm ",[68,130,131],{"style":78},"install --save-dev ",[68,133,96],{"style":78},[68,135,99],{"style":78},[58,137,140],{"language":60,"filename":138,"code":139,"class":63},"yarn","yarn add -D @kubb\u002Fplugin-fetch",[18,141,142],{"class":66},[68,143,144,147,149,151],{"class":70,"style":71},[68,145,146],{"style":74},"yarn ",[68,148,113],{"style":78},[68,150,96],{"style":78},[68,152,99],{"style":78},[11,154,155,158,159,164,165,168,169,172,173,175,176,182],{},[18,156,157],{},"kubb add"," installs the version the ",[160,161,163],"a",{"href":162},"\u002Fregistry","Kubb registry"," pins and adds ",[18,166,167],{},"pluginFetch()"," to ",[18,170,171],{},"kubb.config.ts",". It needs a ",[18,174,171],{},", so run ",[160,177,179],{"href":178},"\u002Fdocs\u002F5.x\u002Freference\u002Fcommands\u002Finit",[18,180,181],{},"kubb init"," first in a new project.",[49,184,186],{"id":185},"setup","Setup",[188,189,190,205,218],"ul",{},[191,192,193,194,197,198,201,202,47],"li",{},"Add ",[18,195,196],{},"@kubb\u002Fplugin-ts"," for the operation types, or ",[18,199,200],{},"@kubb\u002Fplugin-zod"," with ",[18,203,204],{},"inferred: true",[191,206,193,207,209,210,213,214,217],{},[18,208,200],{}," and install ",[18,211,212],{},"zod"," v4 when you set ",[18,215,216],{},"validator",". Generation fails without the plugin.",[191,219,220,221,47],{},"No HTTP client package is needed. The generated code calls the global ",[18,222,46],{},[49,224,226],{"id":225},"options-worth-knowing","Options worth knowing",[228,229,230,243],"table",{},[231,232,233],"thead",{},[234,235,236,240],"tr",{},[237,238,239],"th",{},"Option",[237,241,242],{},"Set it to",[244,245,246,261,277,290,303],"tbody",{},[234,247,248,254],{},[249,250,251],"td",{},[18,252,253],{},"baseURL",[249,255,256,257,260],{},"The starting host. The spec's top-level ",[18,258,259],{},"servers"," URL is not used.",[234,262,263,267],{},[249,264,265],{},[18,266,216],{},[249,268,269,272,273,276],{},[18,270,271],{},"'zod'"," to check response bodies, or ",[18,274,275],{},"{ request, params, response }"," per part.",[234,278,279,284],{},[249,280,281],{},[18,282,283],{},"throwOnErrorDefault",[249,285,286,289],{},[18,287,288],{},"false"," to return non-2xx responses as values.",[234,291,292,297],{},[249,293,294],{},[18,295,296],{},"returnType",[249,298,299,302],{},[18,300,301],{},"'data'"," to resolve to the success body instead of the full result.",[234,304,305,310],{},[249,306,307],{},[18,308,309],{},"sdk",[249,311,312,313,47],{},"Classes instead of functions. Leave it unset for the query plugins and ",[18,314,38],{},[11,316,317,318,322,323,47],{},"Next, ",[160,319,321],{"href":320},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-fetch\u002Fguides\u002Fcalling-operations","call operations",", or see every option and its default in ",[160,324,326],{"href":325},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-fetch\u002Foptions","Options",[49,328,330],{"id":329},"example","Example",[54,332,333,537,601],{},[58,334,337],{"language":335,"filename":171,"code":336,"class":63},"typescript","import { defineConfig } from 'kubb\u002Fconfig'\nimport { adapterOas } from '@kubb\u002Fadapter-oas'\nimport { pluginTs } from '@kubb\u002Fplugin-ts'\nimport { pluginFetch } from '@kubb\u002Fplugin-fetch'\n\nexport default defineConfig({\n input: '.\u002FpetStore.yaml',\n output: { path: '.\u002Fsrc\u002Fgen' },\n adapter: adapterOas({ integerType: 'number' }),\n plugins: [pluginTs(), pluginFetch({ baseURL: 'https:\u002F\u002Fpetstore.swagger.io\u002Fv2' })],\n})",[18,338,340,363,364,363,380,363,396,363,412,363,414,363,428,363,445,363,468,363,496,363,533],{"class":339},"language-typescript",[68,341,342,346,350,353,356,359],{"class":70,"style":71},[68,343,345],{"style":344},"color:#d73a49;--hls-dark:#f97583","import ",[68,347,349],{"style":348},"color:#005cc5;--hls-dark:#79b8ff","{ ",[68,351,352],{"style":78},"defineConfig ",[68,354,355],{"style":348},"} ",[68,357,358],{"style":344},"from ",[68,360,362],{"style":361},"color:#032f62;--hls-dark:#9ecbff","'kubb\u002Fconfig'","\n",[68,365,366,368,370,373,375,377],{"class":70,"style":71},[68,367,345],{"style":344},[68,369,349],{"style":348},[68,371,372],{"style":78},"adapterOas ",[68,374,355],{"style":348},[68,376,358],{"style":344},[68,378,379],{"style":361},"'@kubb\u002Fadapter-oas'",[68,381,382,384,386,389,391,393],{"class":70,"style":71},[68,383,345],{"style":344},[68,385,349],{"style":348},[68,387,388],{"style":78},"pluginTs ",[68,390,355],{"style":348},[68,392,358],{"style":344},[68,394,395],{"style":361},"'@kubb\u002Fplugin-ts'",[68,397,398,400,402,405,407,409],{"class":70,"style":71},[68,399,345],{"style":344},[68,401,349],{"style":348},[68,403,404],{"style":78},"pluginFetch ",[68,406,355],{"style":348},[68,408,358],{"style":344},[68,410,411],{"style":361},"'@kubb\u002Fplugin-fetch'",[68,413],{"class":70,"style":71},[68,415,416,419,422,425],{"class":70,"style":71},[68,417,418],{"style":344},"export ",[68,420,421],{"style":344},"default ",[68,423,424],{"style":74},"defineConfig",[68,426,427],{"style":348},"({",[68,429,430,433,436,439,442],{"class":70,"style":71},[68,431,432],{"style":348}," ",[68,434,435],{"style":348},"input",[68,437,438],{"style":344},": ",[68,440,441],{"style":361},"'.\u002FpetStore.yaml'",[68,443,444],{"style":344},",",[68,446,447,449,452,454,456,458,460,463,466],{"class":70,"style":71},[68,448,432],{"style":344},[68,450,451],{"style":348},"output",[68,453,438],{"style":344},[68,455,349],{"style":348},[68,457,20],{"style":348},[68,459,438],{"style":344},[68,461,462],{"style":361},"'.\u002Fsrc\u002Fgen' ",[68,464,465],{"style":348},"}",[68,467,444],{"style":344},[68,469,470,472,475,477,480,483,486,488,491,494],{"class":70,"style":71},[68,471,432],{"style":344},[68,473,474],{"style":348},"adapter",[68,476,438],{"style":344},[68,478,479],{"style":74},"adapterOas",[68,481,482],{"style":348},"({ ",[68,484,485],{"style":348},"integerType",[68,487,438],{"style":344},[68,489,490],{"style":361},"'number' ",[68,492,493],{"style":348},"})",[68,495,444],{"style":344},[68,497,498,500,503,505,508,511,514,516,519,521,523,525,528,531],{"class":70,"style":71},[68,499,432],{"style":344},[68,501,502],{"style":348},"plugins",[68,504,438],{"style":344},[68,506,507],{"style":348},"[",[68,509,510],{"style":74},"pluginTs",[68,512,513],{"style":348},"()",[68,515,21],{"style":344},[68,517,518],{"style":74},"pluginFetch",[68,520,482],{"style":348},[68,522,253],{"style":348},[68,524,438],{"style":344},[68,526,527],{"style":361},"'https:\u002F\u002Fpetstore.swagger.io\u002Fv2' ",[68,529,530],{"style":348},"})]",[68,532,444],{"style":344},[68,534,535],{"class":70,"style":71},[68,536,493],{"style":348},[58,538,541],{"language":335,"filename":539,"code":540,"class":63},"src\u002Fapp.ts","import { getPetById } from '.\u002Fgen\u002Fclients\u002FgetPetById'\n\nconst { data } = await getPetById({ path: { petId: 1 } })",[18,542,543,363,559,363,561],{"class":339},[68,544,545,547,549,552,554,556],{"class":70,"style":71},[68,546,345],{"style":344},[68,548,349],{"style":348},[68,550,551],{"style":78},"getPetById ",[68,553,355],{"style":348},[68,555,358],{"style":344},[68,557,558],{"style":361},"'.\u002Fgen\u002Fclients\u002FgetPetById'",[68,560],{"class":70,"style":71},[68,562,563,566,568,571,573,576,579,582,584,586,588,590,593,595,598],{"class":70,"style":71},[68,564,565],{"style":344},"const ",[68,567,349],{"style":348},[68,569,570],{"style":78},"data ",[68,572,355],{"style":348},[68,574,575],{"style":344},"= ",[68,577,578],{"style":344},"await ",[68,580,581],{"style":74},"getPetById",[68,583,482],{"style":348},[68,585,20],{"style":348},[68,587,438],{"style":344},[68,589,349],{"style":348},[68,591,592],{"style":348},"petId",[68,594,438],{"style":344},[68,596,597],{"style":348},"1 ",[68,599,600],{"style":348},"} })",[58,602,606],{"language":603,"filename":604,"code":605,"class":63},"text","Generated files","src\u002Fgen\u002F\n├── .kubb\u002F # the runtime: client.ts, core.ts, config.ts, serializers\u002F, ...\n├── clients\u002F\n│ ├── getPetById.ts\n│ └── index.ts\n└── types\u002F",[18,607,609,363,614,363,619,363,624,363,629,363,634],{"class":608},"language-text",[68,610,611],{"class":70,"style":71},[68,612,613],{"style":78},"src\u002Fgen\u002F",[68,615,616],{"class":70,"style":71},[68,617,618],{"style":78},"├── .kubb\u002F # the runtime: client.ts, core.ts, config.ts, serializers\u002F, ...",[68,620,621],{"class":70,"style":71},[68,622,623],{"style":78},"├── clients\u002F",[68,625,626],{"class":70,"style":71},[68,627,628],{"style":78},"│ ├── getPetById.ts",[68,630,631],{"class":70,"style":71},[68,632,633],{"style":78},"│ └── index.ts",[68,635,636],{"class":70,"style":71},[68,637,638],{"style":78},"└── types\u002F",[11,640,641,642,648,649,652,653,655,656,659,660,663,664,47],{},"With ",[160,643,645],{"href":644},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fadapter-oas\u002Foptions#integertype",[18,646,647],{},"integerType: 'number'",", an ",[18,650,651],{},"int64"," id such as ",[18,654,592],{}," is a ",[18,657,658],{},"number",". With the default ",[18,661,662],{},"bigint",", pass ",[18,665,666],{},"1n",{"title":668,"searchDepth":669,"depth":669,"links":670},"",5,[671,673,674,675],{"id":51,"depth":672,"text":52},2,{"id":185,"depth":672,"text":186},{"id":225,"depth":672,"text":226},{"id":329,"depth":672,"text":330},"\u002Fextensions\u002Fkubb-labs\u002Fplugin-fetch",1795727680648,"1b64b1eb-29b7-4f90-ad41-6f24721e1669"]