[{"data":1,"prerenderedAt":313},["ShallowReactive",2],{"page:\u002Fextensions\u002Fkubb-labs\u002Fplugin-client\u002Fguides\u002Fcalling-operations":3},{"id":4,"title":5,"body":6,"description":296,"extension":302,"frontmatter":303,"heading":5,"meta":304,"navigation":305,"order":306,"path":307,"seo":308,"sitemap":309,"source":4,"stem":310,"__hash__":311,"hasPopups":312},"extensions\u002Fextensions\u002Fkubb-labs\u002Fplugin-client\u002Fguides\u002Fcalling-operations.md","Call operations",{"type":7,"value":8,"toc":295},"minimark",[9,13,113,131,136,158,262,266,273],[10,11,12],"p",{},"Each generated function takes one grouped options object and returns your client's promise.",[14,15,19],"pre",{"language":16,"code":17,"class":18},"typescript","import { addPet, getPetById } from '.\u002Fgen\u002Fclients'\n\nconst created = await addPet({ body: { name: 'Odie', photoUrls: [] } })\nconsole.log(created.data, created.response.status)\n\nconst pet = await getPetById({ path: { petId: 1n } })","shiki shiki-themes github-light github-dark dark:github-dark",[20,21,23,43,44,43,46,43,74,43,85,43,87],"code",{"class":22},"language-typescript",[24,25,28,32,36,39],"span",{"class":26,"style":27},"line","display: inline",[24,29,31],{"style":30},"color:#D73A49;--shiki-dark:#F97583","import",[24,33,35],{"style":34},"color:#24292E;--shiki-dark:#E1E4E8"," { addPet, getPetById } ",[24,37,38],{"style":30},"from",[24,40,42],{"style":41},"color:#032F62;--shiki-dark:#9ECBFF"," '.\u002Fgen\u002Fclients'","\n",[24,45],{"class":26,"style":27},[24,47,48,51,55,58,61,65,68,71],{"class":26,"style":27},[24,49,50],{"style":30},"const",[24,52,54],{"style":53},"color:#005CC5;--shiki-dark:#79B8FF"," created",[24,56,57],{"style":30}," =",[24,59,60],{"style":30}," await",[24,62,64],{"style":63},"color:#6F42C1;--shiki-dark:#B392F0"," addPet",[24,66,67],{"style":34},"({ body: { name: ",[24,69,70],{"style":41},"'Odie'",[24,72,73],{"style":34},", photoUrls: [] } })",[24,75,76,79,82],{"class":26,"style":27},[24,77,78],{"style":34},"console.",[24,80,81],{"style":63},"log",[24,83,84],{"style":34},"(created.data, created.response.status)",[24,86],{"class":26,"style":27},[24,88,89,91,94,96,98,101,104,107,110],{"class":26,"style":27},[24,90,50],{"style":30},[24,92,93],{"style":53}," pet",[24,95,57],{"style":30},[24,97,60],{"style":30},[24,99,100],{"style":63}," getPetById",[24,102,103],{"style":34},"({ path: { petId: ",[24,105,106],{"style":53},"1",[24,108,109],{"style":30},"n",[24,111,112],{"style":34}," } })",[10,114,115,116,119,120,119,123,126,127,130],{},"The keys are ",[20,117,118],{},"path",", ",[20,121,122],{},"query",[20,124,125],{},"headers",", and ",[20,128,129],{},"body",". Kubb types each from the spec, so a wrong key or value fails at compile time.",[132,133,135],"h2",{"id":134},"errors","Errors",[10,137,138,141,142,145,146,153,154,157],{},[20,139,140],{},"throwOnError"," defaults to ",[20,143,144],{},"true"," (see ",[147,148,150],"a",{"href":149},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-client\u002Foptions#throwonerrordefault",[20,151,152],{},"throwOnErrorDefault","). What that means is up to your client. With the example client, a non-2xx status throws, and ",[20,155,156],{},"throwOnError: false"," returns the error as a value:",[14,159,161],{"language":16,"code":160,"class":18},"const result = await getPetById({ path: { petId: 1n }, throwOnError: false })\n\nif (result.error === undefined) {\n  console.log('pet', result.data.name)\n}\nif (result.error !== undefined) {\n  console.log('failed', result.response.status)\n}",[20,162,163,43,191,43,193,43,210,43,226,43,231,43,244,43,258],{"class":22},[24,164,165,167,170,172,174,176,178,180,182,185,188],{"class":26,"style":27},[24,166,50],{"style":30},[24,168,169],{"style":53}," result",[24,171,57],{"style":30},[24,173,60],{"style":30},[24,175,100],{"style":63},[24,177,103],{"style":34},[24,179,106],{"style":53},[24,181,109],{"style":30},[24,183,184],{"style":34}," }, throwOnError: ",[24,186,187],{"style":53},"false",[24,189,190],{"style":34}," })",[24,192],{"class":26,"style":27},[24,194,195,198,201,204,207],{"class":26,"style":27},[24,196,197],{"style":30},"if",[24,199,200],{"style":34}," (result.error ",[24,202,203],{"style":30},"===",[24,205,206],{"style":53}," undefined",[24,208,209],{"style":34},") {",[24,211,212,215,217,220,223],{"class":26,"style":27},[24,213,214],{"style":34},"  console.",[24,216,81],{"style":63},[24,218,219],{"style":34},"(",[24,221,222],{"style":41},"'pet'",[24,224,225],{"style":34},", result.data.name)",[24,227,228],{"class":26,"style":27},[24,229,230],{"style":34},"}",[24,232,233,235,237,240,242],{"class":26,"style":27},[24,234,197],{"style":30},[24,236,200],{"style":34},[24,238,239],{"style":30},"!==",[24,241,206],{"style":53},[24,243,209],{"style":34},[24,245,246,248,250,252,255],{"class":26,"style":27},[24,247,214],{"style":34},[24,249,81],{"style":63},[24,251,219],{"style":34},[24,253,254],{"style":41},"'failed'",[24,256,257],{"style":34},", result.response.status)",[24,259,260],{"class":26,"style":27},[24,261,230],{"style":34},[132,263,265],{"id":264},"use-a-different-client-for-one-call","Use a different client for one call",[10,267,268,269,272],{},"Pass ",[20,270,271],{},"client"," to send one call through another function:",[14,274,276],{"language":16,"code":275,"class":18},"await getPetById({ path: { petId: 2n }, client: tenantClient })",[20,277,278],{"class":22},[24,279,280,283,285,287,290,292],{"class":26,"style":27},[24,281,282],{"style":30},"await",[24,284,100],{"style":63},[24,286,103],{"style":34},[24,288,289],{"style":53},"2",[24,291,109],{"style":30},[24,293,294],{"style":34}," }, client: tenantClient })",{"title":296,"searchDepth":297,"depth":297,"links":298},"",5,[299,301],{"id":134,"depth":300,"text":135},2,{"id":264,"depth":300,"text":265},"md",{},{},true,null,"\u002Fextensions\u002Fkubb-labs\u002Fplugin-client\u002Fguides\u002Fcalling-operations",{"title":5},{"loc":307},"extensions\u002Fkubb-labs\u002Fplugin-client\u002Fguides\u002Fcalling-operations","HZZFi4qO74g3Mr3y14vb222fTCI497UjYEvmRYXFu-I",false,1792733920635]