[{"data":1,"prerenderedAt":440},["ShallowReactive",2],{"page:\u002Fextensions\u002Fkubb-labs\u002Fplugin-client\u002Fguides\u002Fcalling-operations":3},{"id":4,"frontmatter":5,"title":6,"heading":6,"body":7,"path":439,"source":4},"extensions\u002Fkubb-labs\u002Fplugin-client\u002Fguides\u002Fcalling-operations.md",{},"Call operations",{"type":8,"value":9,"toc":432},"minimark",[10,14,181,196,201,223,382,386,393],[11,12,13],"p",{},"Each generated function takes one grouped options object and returns your client's promise.",[15,16,20],"pre",{"language":17,"code":18,"class":19},"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 } })","highlights",[21,22,24,57,58,57,60,57,106,57,145,57,147],"code",{"class":23},"language-typescript",[25,26,29,33,37,41,44,47,50,53],"span",{"class":27,"style":28},"line","display: inline",[25,30,32],{"style":31},"color:#d73a49;--hls-dark:#f97583","import ",[25,34,36],{"style":35},"color:#005cc5;--hls-dark:#79b8ff","{ ",[25,38,40],{"style":39},"color:#24292e;--hls-dark:#e1e4e8","addPet",[25,42,43],{"style":31},", ",[25,45,46],{"style":39},"getPetById ",[25,48,49],{"style":35},"} ",[25,51,52],{"style":31},"from ",[25,54,56],{"style":55},"color:#032f62;--hls-dark:#9ecbff","'.\u002Fgen\u002Fclients'","\n",[25,59],{"class":27,"style":28},[25,61,62,65,68,71,74,77,80,83,86,88,91,93,96,98,101,103],{"class":27,"style":28},[25,63,64],{"style":31},"const ",[25,66,67],{"style":39},"created ",[25,69,70],{"style":31},"= ",[25,72,73],{"style":31},"await ",[25,75,40],{"style":76},"color:#6f42c1;--hls-dark:#b392f0",[25,78,79],{"style":35},"({ ",[25,81,82],{"style":35},"body",[25,84,85],{"style":31},": ",[25,87,36],{"style":35},[25,89,90],{"style":35},"name",[25,92,85],{"style":31},[25,94,95],{"style":55},"'Odie'",[25,97,43],{"style":31},[25,99,100],{"style":35},"photoUrls",[25,102,85],{"style":31},[25,104,105],{"style":35},"[] } })",[25,107,108,111,114,117,120,123,125,128,130,132,134,137,139,142],{"class":27,"style":28},[25,109,110],{"style":39},"console",[25,112,113],{"style":31},".",[25,115,116],{"style":76},"log",[25,118,119],{"style":35},"(",[25,121,122],{"style":39},"created",[25,124,113],{"style":31},[25,126,127],{"style":35},"data",[25,129,43],{"style":31},[25,131,122],{"style":39},[25,133,113],{"style":31},[25,135,136],{"style":35},"response",[25,138,113],{"style":31},[25,140,141],{"style":35},"status",[25,143,144],{"style":35},")",[25,146],{"class":27,"style":28},[25,148,149,151,154,156,158,161,163,166,168,170,173,175,178],{"class":27,"style":28},[25,150,64],{"style":31},[25,152,153],{"style":39},"pet ",[25,155,70],{"style":31},[25,157,73],{"style":31},[25,159,160],{"style":76},"getPetById",[25,162,79],{"style":35},[25,164,165],{"style":35},"path",[25,167,85],{"style":31},[25,169,36],{"style":35},[25,171,172],{"style":35},"petId",[25,174,85],{"style":31},[25,176,177],{"style":35},"1n ",[25,179,180],{"style":35},"} })",[11,182,183,184,43,186,43,189,192,193,195],{},"The keys are ",[21,185,165],{},[21,187,188],{},"query",[21,190,191],{},"headers",", and ",[21,194,82],{},". Kubb types each from the spec, so a wrong key or value fails at compile time.",[197,198,200],"h2",{"id":199},"errors","Errors",[11,202,203,206,207,210,211,218,219,222],{},[21,204,205],{},"throwOnError"," defaults to ",[21,208,209],{},"true"," (see ",[212,213,215],"a",{"href":214},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-client\u002Foptions#throwonerrordefault",[21,216,217],{},"throwOnErrorDefault","). What that means is up to your client. With the example client, a non-2xx status throws, and ",[21,220,221],{},"throwOnError: false"," returns the error as a value:",[15,224,226],{"language":17,"code":225,"class":19},"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}",[21,227,228,57,270,57,272,57,296,57,326,57,330,57,349,57,378],{"class":23},[25,229,230,232,235,237,239,241,243,245,247,249,251,253,255,258,260,262,264,267],{"class":27,"style":28},[25,231,64],{"style":31},[25,233,234],{"style":39},"result ",[25,236,70],{"style":31},[25,238,73],{"style":31},[25,240,160],{"style":76},[25,242,79],{"style":35},[25,244,165],{"style":35},[25,246,85],{"style":31},[25,248,36],{"style":35},[25,250,172],{"style":35},[25,252,85],{"style":31},[25,254,177],{"style":35},[25,256,257],{"style":35},"}",[25,259,43],{"style":31},[25,261,205],{"style":35},[25,263,85],{"style":31},[25,265,266],{"style":35},"false ",[25,268,269],{"style":35},"})",[25,271],{"class":27,"style":28},[25,273,274,277,279,282,284,287,290,293],{"class":27,"style":28},[25,275,276],{"style":31},"if ",[25,278,119],{"style":35},[25,280,281],{"style":39},"result",[25,283,113],{"style":31},[25,285,286],{"style":35},"error ",[25,288,289],{"style":31},"=== ",[25,291,292],{"style":35},"undefined",[25,294,295],{"style":35},") {",[25,297,298,301,303,305,307,309,312,314,316,318,320,322,324],{"class":27,"style":28},[25,299,300],{"style":35},"  ",[25,302,110],{"style":39},[25,304,113],{"style":31},[25,306,116],{"style":76},[25,308,119],{"style":35},[25,310,311],{"style":55},"'pet'",[25,313,43],{"style":31},[25,315,281],{"style":39},[25,317,113],{"style":31},[25,319,127],{"style":35},[25,321,113],{"style":31},[25,323,90],{"style":35},[25,325,144],{"style":35},[25,327,328],{"class":27,"style":28},[25,329,257],{"style":35},[25,331,332,334,336,338,340,342,345,347],{"class":27,"style":28},[25,333,276],{"style":31},[25,335,119],{"style":35},[25,337,281],{"style":39},[25,339,113],{"style":31},[25,341,286],{"style":35},[25,343,344],{"style":31},"!== ",[25,346,292],{"style":35},[25,348,295],{"style":35},[25,350,351,353,355,357,359,361,364,366,368,370,372,374,376],{"class":27,"style":28},[25,352,300],{"style":35},[25,354,110],{"style":39},[25,356,113],{"style":31},[25,358,116],{"style":76},[25,360,119],{"style":35},[25,362,363],{"style":55},"'failed'",[25,365,43],{"style":31},[25,367,281],{"style":39},[25,369,113],{"style":31},[25,371,136],{"style":35},[25,373,113],{"style":31},[25,375,141],{"style":35},[25,377,144],{"style":35},[25,379,380],{"class":27,"style":28},[25,381,257],{"style":35},[197,383,385],{"id":384},"use-a-different-client-for-one-call","Use a different client for one call",[11,387,388,389,392],{},"Pass ",[21,390,391],{},"client"," to send one call through another function:",[15,394,396],{"language":17,"code":395,"class":19},"await getPetById({ path: { petId: 2n }, client: tenantClient })",[21,397,398],{"class":23},[25,399,400,402,404,406,408,410,412,414,416,419,421,423,425,427,430],{"class":27,"style":28},[25,401,73],{"style":31},[25,403,160],{"style":76},[25,405,79],{"style":35},[25,407,165],{"style":35},[25,409,85],{"style":31},[25,411,36],{"style":35},[25,413,172],{"style":35},[25,415,85],{"style":31},[25,417,418],{"style":35},"2n ",[25,420,257],{"style":35},[25,422,43],{"style":31},[25,424,391],{"style":35},[25,426,85],{"style":31},[25,428,429],{"style":39},"tenantClient ",[25,431,269],{"style":35},{"title":433,"searchDepth":434,"depth":434,"links":435},"",5,[436,438],{"id":199,"depth":437,"text":200},2,{"id":384,"depth":437,"text":385},"\u002Fextensions\u002Fkubb-labs\u002Fplugin-client\u002Fguides\u002Fcalling-operations",1793747914419]