[{"data":1,"prerenderedAt":487},["ShallowReactive",2],{"page:\u002Fextensions\u002Fkubb-labs\u002Fplugin-fetch":3},{"id":4,"frontmatter":5,"title":6,"heading":6,"body":7,"path":486,"source":4},"extensions\u002Fkubb-labs\u002Fplugin-fetch\u002Findex.md",{},"Fetch",{"type":8,"value":9,"toc":477},"minimark",[10,30,61,66,152,173,177,217,221,283,291,295,298],[11,12,13,14,18,19,18,22,25,26,29],"p",{},"The Fetch plugin turns each operation in your OpenAPI spec into a typed async function that sends the request with the native Fetch API. Each function takes grouped ",[15,16,17],"code",{},"path",", ",[15,20,21],{},"query",[15,23,24],{},"headers",", and ",[15,27,28],{},"body"," parameters and returns a result keyed by status code.",[11,31,32,33,18,36,25,39,42,43,46,47,18,50,25,53,56,57,60],{},"The query plugins (",[15,34,35],{},"@kubb\u002Fplugin-react-query",[15,37,38],{},"@kubb\u002Fplugin-vue-query",[15,40,41],{},"@kubb\u002Fplugin-swr",") and ",[15,44,45],{},"@kubb\u002Fplugin-mcp"," call these functions. The plugin also copies its runtime files (",[15,48,49],{},"client.ts",[15,51,52],{},"serializers.ts",[15,54,55],{},"standardSchema.ts",") to ",[15,58,59],{},".kubb\u002F"," in the root output folder.",[62,63,65],"h2",{"id":64},"installation","Installation",[67,68,70,99,117,135],"code-group",{"sync":69},"package-manager",[71,72,77],"pre",{"language":73,"filename":74,"code":75,"class":76},"shell","bun","bun add -d @kubb\u002Fplugin-fetch","highlights",[15,78,80],{"class":79},"language-shell",[81,82,85,89,93,96],"span",{"class":83,"style":84},"line","display: inline",[81,86,88],{"style":87},"color:#6f42c1;--hls-dark:#b392f0","bun ",[81,90,92],{"style":91},"color:#24292e;--hls-dark:#e1e4e8","add -d ",[81,94,95],{"style":91},"@",[81,97,98],{"style":91},"kubb\u002Fplugin-fetch",[71,100,103],{"language":73,"filename":101,"code":102,"class":76},"pnpm","pnpm add -D @kubb\u002Fplugin-fetch",[15,104,105],{"class":79},[81,106,107,110,113,115],{"class":83,"style":84},[81,108,109],{"style":87},"pnpm ",[81,111,112],{"style":91},"add -D ",[81,114,95],{"style":91},[81,116,98],{"style":91},[71,118,121],{"language":73,"filename":119,"code":120,"class":76},"npm","npm install --save-dev @kubb\u002Fplugin-fetch",[15,122,123],{"class":79},[81,124,125,128,131,133],{"class":83,"style":84},[81,126,127],{"style":87},"npm ",[81,129,130],{"style":91},"install --save-dev ",[81,132,95],{"style":91},[81,134,98],{"style":91},[71,136,139],{"language":73,"filename":137,"code":138,"class":76},"yarn","yarn add -D @kubb\u002Fplugin-fetch",[15,140,141],{"class":79},[81,142,143,146,148,150],{"class":83,"style":84},[81,144,145],{"style":87},"yarn ",[81,147,112],{"style":91},[81,149,95],{"style":91},[81,151,98],{"style":91},[11,153,154,155,158,159,164,165,168,169,172],{},"Or run ",[15,156,157],{},"kubb add plugin-fetch"," to install the version the ",[160,161,163],"a",{"href":162},"\u002Fregistry","Kubb registry"," pins and add ",[15,166,167],{},"pluginFetch()"," to ",[15,170,171],{},"kubb.config.ts",".",[62,174,176],{"id":175},"setup","Setup",[178,179,180,195,211],"ul",{},[181,182,183,184,187,188,191,192,172],"li",{},"Add ",[15,185,186],{},"@kubb\u002Fplugin-ts"," for the operation types, or ",[15,189,190],{},"@kubb\u002Fplugin-zod"," with ",[15,193,194],{},"inferred: true",[181,196,183,197,199,200,203,204,207,208,210],{},[15,198,190],{}," when you set ",[15,201,202],{},"validator",", and install ",[15,205,206],{},"zod"," v4. Without the plugin, ",[15,209,202],{}," does nothing.",[181,212,213,214,172],{},"No HTTP client package is needed. The generated code calls the global ",[15,215,216],{},"fetch",[62,218,220],{"id":219},"options-worth-knowing","Options worth knowing",[178,222,223,239,252,261,271],{},[181,224,225,228,229,232,233,235,236,172],{},[15,226,227],{},"baseURL"," is prepended to every request. The spec's ",[15,230,231],{},"servers"," URL is not used, so without ",[15,234,227],{}," you set one at runtime with ",[15,237,238],{},"client.setConfig({ baseURL })",[181,240,241,244,245,247,248,251],{},[15,242,243],{},"validator: 'zod'"," validates response bodies with the schemas from ",[15,246,190],{},". Use ",[15,249,250],{},"{ request: 'zod', response: 'zod' }"," to also validate request bodies.",[181,253,254,257,258,172],{},[15,255,256],{},"throwOnErrorDefault: false"," returns non-2xx responses as values instead of throwing. A single call can still pass ",[15,259,260],{},"throwOnError",[181,262,263,266,267,270],{},[15,264,265],{},"returnType: 'data'"," makes a call resolve to the success body instead of the full result. With ",[15,268,269],{},"throwOnError: false",", the call still returns the full result.",[181,272,273,276,277,279,280,282],{},[15,274,275],{},"sdk"," generates a class-based SDK, grouped by tag or flat, instead of standalone functions. The query plugins and ",[15,278,45],{}," need the standalone functions, so leave ",[15,281,275],{}," unset when you use them.",[11,284,285,286,290],{},"See ",[160,287,289],{"href":288},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-fetch\u002Foptions","Options"," for every option and its default.",[62,292,294],{"id":293},"example","Example",[11,296,297],{},"The config below generates a Fetch client that sends every request to the Petstore API.",[71,299,302],{"language":300,"filename":171,"code":301,"class":76},"typescript","import { defineConfig } from 'kubb\u002Fconfig'\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  plugins: [\n    pluginTs(),\n    pluginFetch({ baseURL: 'https:\u002F\u002Fpetstore.swagger.io\u002Fv2' }),\n  ],\n})",[15,303,305,328,329,328,345,328,361,328,363,328,377,328,394,328,417,328,429,328,442,328,464,328,473],{"class":304},"language-typescript",[81,306,307,311,315,318,321,324],{"class":83,"style":84},[81,308,310],{"style":309},"color:#d73a49;--hls-dark:#f97583","import ",[81,312,314],{"style":313},"color:#005cc5;--hls-dark:#79b8ff","{ ",[81,316,317],{"style":91},"defineConfig ",[81,319,320],{"style":313},"} ",[81,322,323],{"style":309},"from ",[81,325,327],{"style":326},"color:#032f62;--hls-dark:#9ecbff","'kubb\u002Fconfig'","\n",[81,330,331,333,335,338,340,342],{"class":83,"style":84},[81,332,310],{"style":309},[81,334,314],{"style":313},[81,336,337],{"style":91},"pluginTs ",[81,339,320],{"style":313},[81,341,323],{"style":309},[81,343,344],{"style":326},"'@kubb\u002Fplugin-ts'",[81,346,347,349,351,354,356,358],{"class":83,"style":84},[81,348,310],{"style":309},[81,350,314],{"style":313},[81,352,353],{"style":91},"pluginFetch ",[81,355,320],{"style":313},[81,357,323],{"style":309},[81,359,360],{"style":326},"'@kubb\u002Fplugin-fetch'",[81,362],{"class":83,"style":84},[81,364,365,368,371,374],{"class":83,"style":84},[81,366,367],{"style":309},"export ",[81,369,370],{"style":309},"default ",[81,372,373],{"style":87},"defineConfig",[81,375,376],{"style":313},"({",[81,378,379,382,385,388,391],{"class":83,"style":84},[81,380,381],{"style":313},"  ",[81,383,384],{"style":313},"input",[81,386,387],{"style":309},": ",[81,389,390],{"style":326},"'.\u002FpetStore.yaml'",[81,392,393],{"style":309},",",[81,395,396,398,401,403,405,407,409,412,415],{"class":83,"style":84},[81,397,381],{"style":309},[81,399,400],{"style":313},"output",[81,402,387],{"style":309},[81,404,314],{"style":313},[81,406,17],{"style":313},[81,408,387],{"style":309},[81,410,411],{"style":326},"'.\u002Fsrc\u002Fgen' ",[81,413,414],{"style":313},"}",[81,416,393],{"style":309},[81,418,419,421,424,426],{"class":83,"style":84},[81,420,381],{"style":309},[81,422,423],{"style":313},"plugins",[81,425,387],{"style":309},[81,427,428],{"style":313},"[",[81,430,431,434,437,440],{"class":83,"style":84},[81,432,433],{"style":313},"    ",[81,435,436],{"style":87},"pluginTs",[81,438,439],{"style":313},"()",[81,441,393],{"style":309},[81,443,444,446,449,452,454,456,459,462],{"class":83,"style":84},[81,445,433],{"style":309},[81,447,448],{"style":87},"pluginFetch",[81,450,451],{"style":313},"({ ",[81,453,227],{"style":313},[81,455,387],{"style":309},[81,457,458],{"style":326},"'https:\u002F\u002Fpetstore.swagger.io\u002Fv2' ",[81,460,461],{"style":313},"})",[81,463,393],{"style":309},[81,465,466,468,471],{"class":83,"style":84},[81,467,381],{"style":309},[81,469,470],{"style":313},"]",[81,472,393],{"style":309},[81,474,475],{"class":83,"style":84},[81,476,461],{"style":313},{"title":478,"searchDepth":479,"depth":479,"links":480},"",5,[481,483,484,485],{"id":64,"depth":482,"text":65},2,{"id":175,"depth":482,"text":176},{"id":219,"depth":482,"text":220},{"id":293,"depth":482,"text":294},"\u002Fextensions\u002Fkubb-labs\u002Fplugin-fetch",1793747912129]