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