[{"data":1,"prerenderedAt":2205,"buildId":2206},["ShallowReactive",2],{"page:\u002Fextensions\u002Fkubb-labs\u002Fplugin-fetch\u002Fguides\u002Fconfigure-requests":3},{"id":4,"frontmatter":5,"title":6,"heading":6,"body":7,"path":2204,"source":4},"extensions\u002Fkubb-labs\u002Fplugin-fetch\u002Fguides\u002Fconfigure-requests.md",{},"Configure requests",{"type":8,"value":9,"toc":2187},"minimark",[10,14,19,31,116,157,388,392,395,468,483,495,499,514,602,608,749,760,771,775,781,860,1207,1251,1264,1393,1404,1411,1415,1421,1518,1528,1677,1864,1874,1912,1922,1926,1930,1957,1973,1976,1986,2100,2103,2116,2125,2164,2167,2184],[11,12,13],"p",{},"Set the base URL, credentials, shared headers, and interceptors on the generated Fetch client, for every call or for one.",[15,16,18],"h2",{"id":17},"where-settings-apply","Where settings apply",[11,20,21,22,26,27,30],{},"Every generated function sends through the shared ",[23,24,25],"code",{},"client"," from ",[23,28,29],{},".kubb\u002Fclient.ts",", unless a call passes its own:",[32,33,34,50],"table",{},[35,36,37],"thead",{},[38,39,40,44,47],"tr",{},[41,42,43],"th",{},"Scope",[41,45,46],{},"How",[41,48,49],{},"Effect",[51,52,53,79,92,105],"tbody",{},[38,54,55,59,64],{},[56,57,58],"td",{},"Every call",[56,60,61],{},[23,62,63],{},"client.setConfig({ ... })",[56,65,66,67,70,71,74,75,78],{},"Merges into the shared config. ",[23,68,69],{},"headers",", ",[23,72,73],{},"mediaTypes",", and ",[23,76,77],{},"serializer"," merge per key.",[38,80,81,84,89],{},[56,82,83],{},"A separate client",[56,85,86],{},[23,87,88],{},"createClient({ ... })",[56,90,91],{},"Copies the shared config at creation, without its interceptors.",[38,93,94,97,102],{},[56,95,96],{},"A child client",[56,98,99],{},[23,100,101],{},"client.extend({ ... })",[56,103,104],{},"Copies the shared config and runs the parent's interceptors first.",[38,106,107,110,113],{},[56,108,109],{},"One call",[56,111,112],{},"The same key on the call",[56,114,115],{},"Wins over the client for that call.",[11,117,118,119,70,122,70,124,70,127,70,130,70,133,70,136,70,138,70,140,70,143,74,146,149,150,152,153,156],{},"The client takes ",[23,120,121],{},"baseURL",[23,123,69],{},[23,125,126],{},"auth",[23,128,129],{},"credentials",[23,131,132],{},"options",[23,134,135],{},"transport",[23,137,77],{},[23,139,73],{},[23,141,142],{},"validate",[23,144,145],{},"onValidationError",[23,147,148],{},"retry",". ",[23,151,69],{}," is a record, an array of pairs, or a ",[23,154,155],{},"Headers"," instance:",[158,159,163],"pre",{"language":160,"code":161,"class":162},"typescript","import { client, createClient } from '.\u002Fgen\u002F.kubb\u002Fclient'\nimport { getPetById } from '.\u002Fgen\u002Fclients\u002FgetPetById'\n\nclient.setConfig({ baseURL: import.meta.env.VITE_API_URL, headers: { 'X-Client': 'web' } })\n\nconst tenant = createClient({ baseURL: 'https:\u002F\u002Ftenant.example.com', auth: () => tenantToken })\nawait getPetById({ path: { petId: 1 }, client: tenant })\n\nawait getPetById({ path: { petId: 1 }, baseURL: 'http:\u002F\u002Flocalhost:3000' })","highlights",[23,164,166,197,198,197,214,197,216,197,272,197,274,197,315,197,353,197,355],{"class":165},"language-typescript",[167,168,171,175,179,182,184,187,190,193],"span",{"class":169,"style":170},"line","display: inline",[167,172,174],{"style":173},"color:#d73a49;--hls-dark:#f97583","import ",[167,176,178],{"style":177},"color:#005cc5;--hls-dark:#79b8ff","{ ",[167,180,25],{"style":181},"color:#24292e;--hls-dark:#e1e4e8",[167,183,70],{"style":173},[167,185,186],{"style":181},"createClient ",[167,188,189],{"style":177},"} ",[167,191,192],{"style":173},"from ",[167,194,196],{"style":195},"color:#032f62;--hls-dark:#9ecbff","'.\u002Fgen\u002F.kubb\u002Fclient'","\n",[167,199,200,202,204,207,209,211],{"class":169,"style":170},[167,201,174],{"style":173},[167,203,178],{"style":177},[167,205,206],{"style":181},"getPetById ",[167,208,189],{"style":177},[167,210,192],{"style":173},[167,212,213],{"style":195},"'.\u002Fgen\u002Fclients\u002FgetPetById'",[167,215],{"class":169,"style":170},[167,217,218,220,223,227,230,232,235,238,240,243,245,248,250,253,255,257,259,261,264,266,269],{"class":169,"style":170},[167,219,25],{"style":181},[167,221,222],{"style":173},".",[167,224,226],{"style":225},"color:#6f42c1;--hls-dark:#b392f0","setConfig",[167,228,229],{"style":177},"({ ",[167,231,121],{"style":177},[167,233,234],{"style":173},": ",[167,236,237],{"style":173},"import",[167,239,222],{"style":173},[167,241,242],{"style":177},"meta",[167,244,222],{"style":173},[167,246,247],{"style":177},"env",[167,249,222],{"style":173},[167,251,252],{"style":177},"VITE_API_URL",[167,254,70],{"style":173},[167,256,69],{"style":177},[167,258,234],{"style":173},[167,260,178],{"style":177},[167,262,263],{"style":195},"'X-Client'",[167,265,234],{"style":173},[167,267,268],{"style":195},"'web' ",[167,270,271],{"style":177},"} })",[167,273],{"class":169,"style":170},[167,275,276,279,282,285,288,290,292,294,297,299,301,303,306,309,312],{"class":169,"style":170},[167,277,278],{"style":173},"const ",[167,280,281],{"style":181},"tenant ",[167,283,284],{"style":173},"= ",[167,286,287],{"style":225},"createClient",[167,289,229],{"style":177},[167,291,121],{"style":177},[167,293,234],{"style":173},[167,295,296],{"style":195},"'https:\u002F\u002Ftenant.example.com'",[167,298,70],{"style":173},[167,300,126],{"style":177},[167,302,234],{"style":173},[167,304,305],{"style":177},"() ",[167,307,308],{"style":173},"=> ",[167,310,311],{"style":181},"tenantToken ",[167,313,314],{"style":177},"})",[167,316,317,320,323,325,328,330,332,335,337,340,343,345,347,349,351],{"class":169,"style":170},[167,318,319],{"style":173},"await ",[167,321,322],{"style":225},"getPetById",[167,324,229],{"style":177},[167,326,327],{"style":177},"path",[167,329,234],{"style":173},[167,331,178],{"style":177},[167,333,334],{"style":177},"petId",[167,336,234],{"style":173},[167,338,339],{"style":177},"1 ",[167,341,342],{"style":177},"}",[167,344,70],{"style":173},[167,346,25],{"style":177},[167,348,234],{"style":173},[167,350,281],{"style":181},[167,352,314],{"style":177},[167,354],{"class":169,"style":170},[167,356,357,359,361,363,365,367,369,371,373,375,377,379,381,383,386],{"class":169,"style":170},[167,358,319],{"style":173},[167,360,322],{"style":225},[167,362,229],{"style":177},[167,364,327],{"style":177},[167,366,234],{"style":173},[167,368,178],{"style":177},[167,370,334],{"style":177},[167,372,234],{"style":173},[167,374,339],{"style":177},[167,376,342],{"style":177},[167,378,70],{"style":173},[167,380,121],{"style":177},[167,382,234],{"style":173},[167,384,385],{"style":195},"'http:\u002F\u002Flocalhost:3000' ",[167,387,314],{"style":177},[15,389,391],{"id":390},"set-the-base-url","Set the base URL",[11,393,394],{},"A call uses the first base URL it finds:",[32,396,397,407],{},[35,398,399],{},[38,400,401,404],{},[41,402,403],{},"Order",[41,405,406],{},"Source",[51,408,409,419,433,443,453],{},[38,410,411,414],{},[56,412,413],{},"1",[56,415,416,418],{},[23,417,121],{}," on the call.",[38,420,421,424],{},[56,422,423],{},"2",[56,425,426,427,430,431,222],{},"The operation's own ",[23,428,429],{},"servers",", then its path's ",[23,432,429],{},[38,434,435,438],{},[56,436,437],{},"3",[56,439,440,441,222],{},"The client passed as ",[23,442,25],{},[38,444,445,448],{},[56,446,447],{},"4",[56,449,450,222],{},[23,451,452],{},"client.setConfig({ baseURL })",[38,454,455,458],{},[56,456,457],{},"5",[56,459,460,461,467],{},"The plugin's ",[462,463,465],"a",{"href":464},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-fetch\u002Foptions#baseurl",[23,466,121],{}," option.",[469,470,472,473,475,476,479,480,222],"blockquote",{"as":471},"note","The spec's top-level ",[23,474,429],{}," URL is never used, even with the ",[23,477,478],{},"server"," option of ",[23,481,482],{},"adapterOas",[11,484,485,486,490,491,222],{},"See ",[462,487,489],{"href":488},"#which-server-a-call-picks","Which server a call picks"," and ",[462,492,494],{"href":493},"#named-servers","Named servers",[15,496,498],{"id":497},"authenticate-requests","Authenticate requests",[11,500,501,502,504,505,509,510,513],{},"Set ",[23,503,126],{}," to a token, or to a sync or async function that gets each ",[462,506,508],{"href":507},"https:\u002F\u002Fspec.openapis.org\u002Foas\u002Fv3.1.0#security-scheme-object","security scheme"," of the call. It returns the token, or ",[23,511,512],{},"undefined"," to skip the scheme:",[158,515,517],{"language":160,"code":516,"class":162},"client.setConfig({\n auth: (auth) => (auth.type === 'apiKey' ? apiKey : localStorage.getItem('token') ?? undefined),\n})",[23,518,519,197,530,197,598],{"class":165},[167,520,521,523,525,527],{"class":169,"style":170},[167,522,25],{"style":181},[167,524,222],{"style":173},[167,526,226],{"style":225},[167,528,529],{"style":177},"({",[167,531,532,535,537,539,542,544,547,549,551,553,555,558,561,564,567,570,572,575,577,580,582,585,587,590,592,595],{"class":169,"style":170},[167,533,534],{"style":177}," ",[167,536,126],{"style":177},[167,538,234],{"style":173},[167,540,541],{"style":177},"(",[167,543,126],{"style":181},[167,545,546],{"style":177},") ",[167,548,308],{"style":173},[167,550,541],{"style":177},[167,552,126],{"style":181},[167,554,222],{"style":173},[167,556,557],{"style":177},"type ",[167,559,560],{"style":173},"=== ",[167,562,563],{"style":195},"'apiKey' ",[167,565,566],{"style":173},"? ",[167,568,569],{"style":181},"apiKey ",[167,571,234],{"style":173},[167,573,574],{"style":181},"localStorage",[167,576,222],{"style":173},[167,578,579],{"style":225},"getItem",[167,581,541],{"style":177},[167,583,584],{"style":195},"'token'",[167,586,546],{"style":177},[167,588,589],{"style":173},"?? ",[167,591,512],{"style":177},[167,593,594],{"style":177},")",[167,596,597],{"style":173},",",[167,599,600],{"class":169,"style":170},[167,601,314],{"style":177},[11,603,604,605,607],{},"By default, ",[23,606,126],{}," adds no credentials. The scheme decides where the token goes:",[32,609,610,625],{},[35,611,612],{},[38,613,614,617,622],{},[41,615,616],{},"Scheme in the spec",[41,618,619,621],{},[23,620,126],{}," gets",[41,623,624],{},"The token goes to",[51,626,627,645,662,681,698,717,733],{},[38,628,629,635,640],{},[56,630,631,634],{},[23,632,633],{},"http"," bearer",[56,636,637],{},[23,638,639],{},"{ type: 'http', scheme: 'bearer' }",[56,641,642],{},[23,643,644],{},"Authorization: Bearer \u003Ctoken>",[38,646,647,652,657],{},[56,648,649,651],{},[23,650,633],{}," basic",[56,653,654],{},[23,655,656],{},"{ type: 'http', scheme: 'basic' }",[56,658,659],{},[23,660,661],{},"Authorization: Basic \u003Cbase64>",[38,663,664,670,675],{},[56,665,666,669],{},[23,667,668],{},"apiKey"," in header",[56,671,672],{},[23,673,674],{},"{ type: 'apiKey', name, in: 'header' }",[56,676,677,678],{},"the header named ",[23,679,680],{},"name",[38,682,683,688,693],{},[56,684,685,687],{},[23,686,668],{}," in query",[56,689,690],{},[23,691,692],{},"{ type: 'apiKey', name, in: 'query' }",[56,694,695,696],{},"the query parameter ",[23,697,680],{},[38,699,700,705,710],{},[56,701,702,704],{},[23,703,668],{}," in cookie",[56,706,707],{},[23,708,709],{},"{ type: 'apiKey', name, in: 'cookie' }",[56,711,712,713,716],{},"the ",[23,714,715],{},"Cookie"," header",[38,718,719,724,729],{},[56,720,721],{},[23,722,723],{},"oauth2",[56,725,726],{},[23,727,728],{},"{ type: 'oauth2', scopes, flows }",[56,730,731],{},[23,732,644],{},[38,734,735,740,745],{},[56,736,737],{},[23,738,739],{},"openIdConnect",[56,741,742],{},[23,743,744],{},"{ type: 'openIdConnect', scopes, url }",[56,746,747],{},[23,748,644],{},[469,750,751,752,755,756,759],{"as":471},"For basic auth, return the raw ",[23,753,754],{},"username:password",". The runtime base64-encodes it and adds the ",[23,757,758],{},"Basic"," prefix.",[11,761,762,763,490,767,222],{},"For a credential that no security scheme describes, such as a request signature, add a request interceptor. See ",[462,764,766],{"href":765},"#several-security-schemes","Several security schemes",[462,768,770],{"href":769},"#mutual-tls","Mutual TLS",[15,772,774],{"id":773},"add-interceptors","Add interceptors",[11,776,777,780],{},[23,778,779],{},"client.interceptors"," has three stacks. Each handler gets the value the one before it returned:",[32,782,783,799],{},[35,784,785],{},[38,786,787,790,793,796],{},[41,788,789],{},"Stack",[41,791,792],{},"Runs",[41,794,795],{},"Gets",[41,797,798],{},"Returns",[51,800,801,819,837],{},[38,802,803,808,811,816],{},[56,804,805],{},[23,806,807],{},"request",[56,809,810],{},"After the URL, body, and auth are built, before the send.",[56,812,813],{},[23,814,815],{},"ResolvedRequest",[56,817,818],{},"The request, or nothing to keep it.",[38,820,821,826,829,834],{},[56,822,823],{},[23,824,825],{},"response",[56,827,828],{},"After the body is decoded, before the status check and validator.",[56,830,831],{},[23,832,833],{},"DecodedResponse",[56,835,836],{},"The result, or nothing to keep it.",[38,838,839,844,854,857],{},[56,840,841],{},[23,842,843],{},"error",[56,845,846,847,850,851,222],{},"When a call fails: ",[23,848,849],{},"ResponseError",", network error, abort, ",[23,852,853],{},"ValidationError",[56,855,856],{},"The error",[56,858,859],{},"Another error to throw, or nothing to keep it.",[861,862,863,943,1034],"code-group",{},[158,864,866],{"language":160,"filename":807,"code":865,"class":162},"client.interceptors.request.use((request) => {\n request.headers['X-Request-ID'] = crypto.randomUUID()\n return request\n})",[23,867,868,197,898,197,930,197,939],{"class":165},[167,869,870,872,874,877,879,881,883,886,889,891,893,895],{"class":169,"style":170},[167,871,25],{"style":181},[167,873,222],{"style":173},[167,875,876],{"style":177},"interceptors",[167,878,222],{"style":173},[167,880,807],{"style":177},[167,882,222],{"style":173},[167,884,885],{"style":225},"use",[167,887,888],{"style":177},"((",[167,890,807],{"style":181},[167,892,546],{"style":177},[167,894,308],{"style":173},[167,896,897],{"style":177},"{",[167,899,900,902,904,906,908,911,914,917,919,922,924,927],{"class":169,"style":170},[167,901,534],{"style":177},[167,903,807],{"style":181},[167,905,222],{"style":173},[167,907,69],{"style":177},[167,909,910],{"style":177},"[",[167,912,913],{"style":195},"'X-Request-ID'",[167,915,916],{"style":177},"] ",[167,918,284],{"style":173},[167,920,921],{"style":181},"crypto",[167,923,222],{"style":173},[167,925,926],{"style":225},"randomUUID",[167,928,929],{"style":177},"()",[167,931,932,934,937],{"class":169,"style":170},[167,933,534],{"style":177},[167,935,936],{"style":173},"return ",[167,938,807],{"style":181},[167,940,941],{"class":169,"style":170},[167,942,314],{"style":177},[158,944,946],{"language":160,"filename":825,"code":945,"class":162},"client.interceptors.response.use((result) => {\n console.info(`${result.status} ${result.contentType}`)\n return result\n})",[23,947,948,197,975,197,1022,197,1030],{"class":165},[167,949,950,952,954,956,958,960,962,964,966,969,971,973],{"class":169,"style":170},[167,951,25],{"style":181},[167,953,222],{"style":173},[167,955,876],{"style":177},[167,957,222],{"style":173},[167,959,825],{"style":177},[167,961,222],{"style":173},[167,963,885],{"style":225},[167,965,888],{"style":177},[167,967,968],{"style":181},"result",[167,970,546],{"style":177},[167,972,308],{"style":173},[167,974,897],{"style":177},[167,976,977,979,982,984,987,989,992,995,997,999,1002,1004,1007,1009,1011,1013,1016,1018,1020],{"class":169,"style":170},[167,978,534],{"style":177},[167,980,981],{"style":181},"console",[167,983,222],{"style":173},[167,985,986],{"style":225},"info",[167,988,541],{"style":177},[167,990,991],{"style":195},"`",[167,993,994],{"style":181},"${",[167,996,968],{"style":181},[167,998,222],{"style":173},[167,1000,1001],{"style":177},"status",[167,1003,342],{"style":181},[167,1005,1006],{"style":195}," ",[167,1008,994],{"style":181},[167,1010,968],{"style":181},[167,1012,222],{"style":173},[167,1014,1015],{"style":177},"contentType",[167,1017,342],{"style":181},[167,1019,991],{"style":195},[167,1021,594],{"style":177},[167,1023,1024,1026,1028],{"class":169,"style":170},[167,1025,534],{"style":177},[167,1027,936],{"style":173},[167,1029,968],{"style":181},[167,1031,1032],{"class":169,"style":170},[167,1033,314],{"style":177},[158,1035,1037],{"language":160,"filename":843,"code":1036,"class":162},"import { client, ResponseError } from '.\u002Fgen\u002F.kubb\u002Fclient'\n\nclass NotFoundError extends Error {}\n\nclient.interceptors.error.use((error) => {\n if (ResponseError.is(error) && error.status === 401) scheduleTokenRefresh()\n if (ResponseError.is(error) && error.status === 404) return new NotFoundError(error.message)\n})",[23,1038,1039,197,1058,197,1060,197,1077,197,1079,197,1105,197,1149,197,1203],{"class":165},[167,1040,1041,1043,1045,1047,1049,1052,1054,1056],{"class":169,"style":170},[167,1042,174],{"style":173},[167,1044,178],{"style":177},[167,1046,25],{"style":181},[167,1048,70],{"style":173},[167,1050,1051],{"style":225},"ResponseError ",[167,1053,189],{"style":177},[167,1055,192],{"style":173},[167,1057,196],{"style":195},[167,1059],{"class":169,"style":170},[167,1061,1062,1065,1068,1071,1074],{"class":169,"style":170},[167,1063,1064],{"style":173},"class ",[167,1066,1067],{"style":225},"NotFoundError ",[167,1069,1070],{"style":173},"extends ",[167,1072,1073],{"style":225},"Error ",[167,1075,1076],{"style":177},"{}",[167,1078],{"class":169,"style":170},[167,1080,1081,1083,1085,1087,1089,1091,1093,1095,1097,1099,1101,1103],{"class":169,"style":170},[167,1082,25],{"style":181},[167,1084,222],{"style":173},[167,1086,876],{"style":177},[167,1088,222],{"style":173},[167,1090,843],{"style":177},[167,1092,222],{"style":173},[167,1094,885],{"style":225},[167,1096,888],{"style":177},[167,1098,843],{"style":181},[167,1100,546],{"style":177},[167,1102,308],{"style":173},[167,1104,897],{"style":177},[167,1106,1107,1109,1112,1114,1116,1118,1121,1123,1125,1127,1130,1132,1134,1137,1139,1142,1144,1147],{"class":169,"style":170},[167,1108,534],{"style":177},[167,1110,1111],{"style":173},"if ",[167,1113,541],{"style":177},[167,1115,849],{"style":225},[167,1117,222],{"style":173},[167,1119,1120],{"style":225},"is",[167,1122,541],{"style":177},[167,1124,843],{"style":181},[167,1126,546],{"style":177},[167,1128,1129],{"style":173},"&& ",[167,1131,843],{"style":181},[167,1133,222],{"style":173},[167,1135,1136],{"style":177},"status ",[167,1138,560],{"style":173},[167,1140,1141],{"style":177},"401",[167,1143,546],{"style":177},[167,1145,1146],{"style":225},"scheduleTokenRefresh",[167,1148,929],{"style":177},[167,1150,1151,1153,1155,1157,1159,1161,1163,1165,1167,1169,1171,1173,1175,1177,1179,1182,1184,1186,1189,1192,1194,1196,1198,1201],{"class":169,"style":170},[167,1152,534],{"style":177},[167,1154,1111],{"style":173},[167,1156,541],{"style":177},[167,1158,849],{"style":225},[167,1160,222],{"style":173},[167,1162,1120],{"style":225},[167,1164,541],{"style":177},[167,1166,843],{"style":181},[167,1168,546],{"style":177},[167,1170,1129],{"style":173},[167,1172,843],{"style":181},[167,1174,222],{"style":173},[167,1176,1136],{"style":177},[167,1178,560],{"style":173},[167,1180,1181],{"style":177},"404",[167,1183,546],{"style":177},[167,1185,936],{"style":173},[167,1187,1188],{"style":173},"new ",[167,1190,1191],{"style":225},"NotFoundError",[167,1193,541],{"style":177},[167,1195,843],{"style":181},[167,1197,222],{"style":173},[167,1199,1200],{"style":177},"message",[167,1202,594],{"style":177},[167,1204,1205],{"class":169,"style":170},[167,1206,314],{"style":177},[11,1208,1209,1211,1212,70,1215,70,1218,70,1220,70,1223,70,1226,70,1228,74,1230,149,1233,1211,1235,70,1238,70,1240,70,1243,70,1245,70,1247,74,1249,222],{},[23,1210,815],{}," has ",[23,1213,1214],{},"url",[23,1216,1217],{},"method",[23,1219,69],{},[23,1221,1222],{},"body",[23,1224,1225],{},"signal",[23,1227,129],{},[23,1229,132],{},[23,1231,1232],{},"stream",[23,1234,833],{},[23,1236,1237],{},"data",[23,1239,1001],{},[23,1241,1242],{},"statusText",[23,1244,69],{},[23,1246,1015],{},[23,1248,807],{},[23,1250,825],{},[11,1252,1253,1254,1256,1257,490,1260,1263],{},"Handlers run in the order you register them. ",[23,1255,885],{}," returns an id for ",[23,1258,1259],{},"eject",[23,1261,1262],{},"update",":",[158,1265,1267],{"language":160,"code":1266,"class":162},"const id = client.interceptors.request.use((request) => request)\nclient.interceptors.request.update(id, (request) => ({ ...request, headers: { ...request.headers, 'X-Trace': 'on' } }))\nclient.interceptors.request.eject(id)",[23,1268,1269,197,1304,197,1371],{"class":165},[167,1270,1271,1273,1276,1278,1280,1282,1284,1286,1288,1290,1292,1294,1296,1298,1300,1302],{"class":169,"style":170},[167,1272,278],{"style":173},[167,1274,1275],{"style":181},"id ",[167,1277,284],{"style":173},[167,1279,25],{"style":181},[167,1281,222],{"style":173},[167,1283,876],{"style":177},[167,1285,222],{"style":173},[167,1287,807],{"style":177},[167,1289,222],{"style":173},[167,1291,885],{"style":225},[167,1293,888],{"style":177},[167,1295,807],{"style":181},[167,1297,546],{"style":177},[167,1299,308],{"style":173},[167,1301,807],{"style":181},[167,1303,594],{"style":177},[167,1305,1306,1308,1310,1312,1314,1316,1318,1320,1322,1325,1327,1329,1331,1333,1335,1337,1340,1342,1344,1346,1348,1350,1352,1354,1356,1358,1360,1363,1365,1368],{"class":169,"style":170},[167,1307,25],{"style":181},[167,1309,222],{"style":173},[167,1311,876],{"style":177},[167,1313,222],{"style":173},[167,1315,807],{"style":177},[167,1317,222],{"style":173},[167,1319,1262],{"style":225},[167,1321,541],{"style":177},[167,1323,1324],{"style":181},"id",[167,1326,70],{"style":173},[167,1328,541],{"style":177},[167,1330,807],{"style":181},[167,1332,546],{"style":177},[167,1334,308],{"style":173},[167,1336,229],{"style":177},[167,1338,1339],{"style":173},"...",[167,1341,807],{"style":181},[167,1343,70],{"style":173},[167,1345,69],{"style":177},[167,1347,234],{"style":173},[167,1349,178],{"style":177},[167,1351,1339],{"style":173},[167,1353,807],{"style":181},[167,1355,222],{"style":173},[167,1357,69],{"style":177},[167,1359,70],{"style":173},[167,1361,1362],{"style":195},"'X-Trace'",[167,1364,234],{"style":173},[167,1366,1367],{"style":195},"'on' ",[167,1369,1370],{"style":177},"} }))",[167,1372,1373,1375,1377,1379,1381,1383,1385,1387,1389,1391],{"class":169,"style":170},[167,1374,25],{"style":181},[167,1376,222],{"style":173},[167,1378,876],{"style":177},[167,1380,222],{"style":173},[167,1382,807],{"style":177},[167,1384,222],{"style":173},[167,1386,1259],{"style":225},[167,1388,541],{"style":177},[167,1390,1324],{"style":181},[167,1392,594],{"style":177},[469,1394,1395,1396,1399,1400,1403],{"as":471},"With ",[23,1397,1398],{},"throwOnError: false",", a non-2xx response resolves, so no error handler runs for it. An error thrown while a stream is read, in the ",[23,1401,1402],{},"for await"," loop, does not reach the error handlers either.",[11,1405,1406,1407,222],{},"Next, ",[462,1408,1410],{"href":1409},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-fetch\u002Fguides\u002Ftransport","use a custom transport",[15,1412,1414],{"id":1413},"retry-a-failed-call","Retry a failed call",[11,1416,1417,1418,1420],{},"Retries are off by default. Set ",[23,1419,148],{}," on the client or on one call. A number is how many times a failed call is sent again:",[158,1422,1424],{"language":160,"code":1423,"class":162},"import { client } from '.\u002Fgen\u002F.kubb\u002Fclient'\n\nclient.setConfig({ retry: 2 })\n\nawait createOrder({ body, retry: { methods: ['POST'] } })\nawait chargeCard({ body, retry: false })",[23,1425,1426,197,1441,197,1443,197,1462,197,1464,197,1496],{"class":165},[167,1427,1428,1430,1432,1435,1437,1439],{"class":169,"style":170},[167,1429,174],{"style":173},[167,1431,178],{"style":177},[167,1433,1434],{"style":181},"client ",[167,1436,189],{"style":177},[167,1438,192],{"style":173},[167,1440,196],{"style":195},[167,1442],{"class":169,"style":170},[167,1444,1445,1447,1449,1451,1453,1455,1457,1460],{"class":169,"style":170},[167,1446,25],{"style":181},[167,1448,222],{"style":173},[167,1450,226],{"style":225},[167,1452,229],{"style":177},[167,1454,148],{"style":177},[167,1456,234],{"style":173},[167,1458,1459],{"style":177},"2 ",[167,1461,314],{"style":177},[167,1463],{"class":169,"style":170},[167,1465,1466,1468,1471,1473,1475,1477,1479,1481,1483,1486,1488,1490,1493],{"class":169,"style":170},[167,1467,319],{"style":173},[167,1469,1470],{"style":225},"createOrder",[167,1472,229],{"style":177},[167,1474,1222],{"style":181},[167,1476,70],{"style":173},[167,1478,148],{"style":177},[167,1480,234],{"style":173},[167,1482,178],{"style":177},[167,1484,1485],{"style":177},"methods",[167,1487,234],{"style":173},[167,1489,910],{"style":177},[167,1491,1492],{"style":195},"'POST'",[167,1494,1495],{"style":177},"] } })",[167,1497,1498,1500,1503,1505,1507,1509,1511,1513,1516],{"class":169,"style":170},[167,1499,319],{"style":173},[167,1501,1502],{"style":225},"chargeCard",[167,1504,229],{"style":177},[167,1506,1222],{"style":181},[167,1508,70],{"style":173},[167,1510,148],{"style":177},[167,1512,234],{"style":173},[167,1514,1515],{"style":177},"false ",[167,1517,314],{"style":177},[11,1519,1520,1521,1523,1524,1527],{},"A call's ",[23,1522,148],{}," merges per field over the client's, and ",[23,1525,1526],{},"false"," sends that call once. Pass an object for more control:",[32,1529,1530,1543],{},[35,1531,1532],{},[38,1533,1534,1537,1540],{},[41,1535,1536],{},"Option",[41,1538,1539],{},"What it does",[41,1541,1542],{},"Default",[51,1544,1545,1559,1588,1618,1638,1662],{},[38,1546,1547,1552,1555],{},[56,1548,1549],{},[23,1550,1551],{},"limit",[56,1553,1554],{},"How many times the call is sent again.",[56,1556,1557],{},[23,1558,423],{},[38,1560,1561,1565,1568],{},[56,1562,1563],{},[23,1564,1485],{},[56,1566,1567],{},"The methods that are safe to send twice.",[56,1569,1570,70,1573,70,1576,70,1579,70,1582,70,1585],{},[23,1571,1572],{},"GET",[23,1574,1575],{},"HEAD",[23,1577,1578],{},"OPTIONS",[23,1580,1581],{},"PUT",[23,1583,1584],{},"DELETE",[23,1586,1587],{},"TRACE",[38,1589,1590,1595,1598],{},[56,1591,1592],{},[23,1593,1594],{},"statusCodes",[56,1596,1597],{},"The statuses that are retried.",[56,1599,1600,70,1603,70,1606,70,1609,70,1612,70,1615],{},[23,1601,1602],{},"408",[23,1604,1605],{},"429",[23,1607,1608],{},"500",[23,1610,1611],{},"502",[23,1613,1614],{},"503",[23,1616,1617],{},"504",[38,1619,1620,1625,1635],{},[56,1621,1622],{},[23,1623,1624],{},"delay",[56,1626,1627,1630,1631,1634],{},[23,1628,1629],{},"(retryCount) => milliseconds"," to wait. ",[23,1632,1633],{},"retryCount"," starts at 1.",[56,1636,1637],{},"Exponential from 300 ms with jitter, up to 30 s",[38,1639,1640,1645,1659],{},[56,1641,1642],{},[23,1643,1644],{},"shouldRetry",[56,1646,1647,1650,1651,70,1654,1656,1657],{},[23,1648,1649],{},"({ request, response, error, retryCount })"," returns ",[23,1652,1653],{},"true",[23,1655,1526],{},", or ",[23,1658,512],{},[56,1660,1661],{},"The status and error check",[38,1663,1664,1669,1674],{},[56,1665,1666],{},[23,1667,1668],{},"onRetry",[56,1670,1671,1672,222],{},"Runs before each wait, with the same context plus ",[23,1673,1624],{},[56,1675,1676],{},"None",[158,1678,1680],{"language":160,"code":1679,"class":162},"client.setConfig({\n retry: {\n limit: 3,\n delay: (retryCount) => 1000 * retryCount,\n shouldRetry: ({ response }) => (response?.headers.get('x-no-retry') === 'true' ? false : undefined),\n onRetry: ({ retryCount, delay }) => console.warn(`Retry ${retryCount} in ${delay} ms`),\n },\n})",[23,1681,1682,197,1692,197,1702,197,1715,197,1741,197,1797,197,1852,197,1860],{"class":165},[167,1683,1684,1686,1688,1690],{"class":169,"style":170},[167,1685,25],{"style":181},[167,1687,222],{"style":173},[167,1689,226],{"style":225},[167,1691,529],{"style":177},[167,1693,1694,1696,1698,1700],{"class":169,"style":170},[167,1695,534],{"style":177},[167,1697,148],{"style":177},[167,1699,234],{"style":173},[167,1701,897],{"style":177},[167,1703,1704,1707,1709,1711,1713],{"class":169,"style":170},[167,1705,1706],{"style":177}," ",[167,1708,1551],{"style":177},[167,1710,234],{"style":173},[167,1712,437],{"style":177},[167,1714,597],{"style":173},[167,1716,1717,1719,1721,1723,1725,1727,1729,1731,1734,1737,1739],{"class":169,"style":170},[167,1718,1706],{"style":173},[167,1720,1624],{"style":177},[167,1722,234],{"style":173},[167,1724,541],{"style":177},[167,1726,1633],{"style":181},[167,1728,546],{"style":177},[167,1730,308],{"style":173},[167,1732,1733],{"style":177},"1000 ",[167,1735,1736],{"style":173},"* ",[167,1738,1633],{"style":181},[167,1740,597],{"style":173},[167,1742,1743,1745,1747,1749,1751,1754,1757,1759,1761,1763,1766,1768,1770,1773,1775,1778,1780,1782,1785,1787,1789,1791,1793,1795],{"class":169,"style":170},[167,1744,1706],{"style":173},[167,1746,1644],{"style":177},[167,1748,234],{"style":173},[167,1750,229],{"style":177},[167,1752,1753],{"style":181},"response ",[167,1755,1756],{"style":177},"}) ",[167,1758,308],{"style":173},[167,1760,541],{"style":177},[167,1762,825],{"style":181},[167,1764,1765],{"style":173},"?.",[167,1767,69],{"style":177},[167,1769,222],{"style":173},[167,1771,1772],{"style":225},"get",[167,1774,541],{"style":177},[167,1776,1777],{"style":195},"'x-no-retry'",[167,1779,546],{"style":177},[167,1781,560],{"style":173},[167,1783,1784],{"style":195},"'true' ",[167,1786,566],{"style":173},[167,1788,1515],{"style":177},[167,1790,234],{"style":173},[167,1792,512],{"style":177},[167,1794,594],{"style":177},[167,1796,597],{"style":173},[167,1798,1799,1801,1803,1805,1807,1809,1811,1814,1816,1818,1820,1822,1825,1827,1830,1832,1834,1836,1839,1841,1843,1845,1848,1850],{"class":169,"style":170},[167,1800,1706],{"style":173},[167,1802,1668],{"style":177},[167,1804,234],{"style":173},[167,1806,229],{"style":177},[167,1808,1633],{"style":181},[167,1810,70],{"style":173},[167,1812,1813],{"style":181},"delay ",[167,1815,1756],{"style":177},[167,1817,308],{"style":173},[167,1819,981],{"style":181},[167,1821,222],{"style":173},[167,1823,1824],{"style":225},"warn",[167,1826,541],{"style":177},[167,1828,1829],{"style":195},"`Retry ",[167,1831,994],{"style":181},[167,1833,1633],{"style":181},[167,1835,342],{"style":181},[167,1837,1838],{"style":195}," in ",[167,1840,994],{"style":181},[167,1842,1624],{"style":181},[167,1844,342],{"style":181},[167,1846,1847],{"style":195}," ms`",[167,1849,594],{"style":177},[167,1851,597],{"style":173},[167,1853,1854,1856,1858],{"class":169,"style":170},[167,1855,534],{"style":173},[167,1857,342],{"style":177},[167,1859,597],{"style":173},[167,1861,1862],{"class":169,"style":170},[167,1863,314],{"style":177},[11,1865,1866,1867,1869,1870,1650,1872,1263],{},"The client retries a status in ",[23,1868,1594],{}," and any error the transport throws. These rules always apply, also when ",[23,1871,1644],{},[23,1873,1653],{},[1875,1876,1877,1890,1893,1900,1906],"ul",{},[1878,1879,1880,490,1883,1886,1887,1889],"li",{},[23,1881,1882],{},"POST",[23,1884,1885],{},"PATCH"," are retried only when ",[23,1888,1485],{}," names them.",[1878,1891,1892],{},"A stream body is never retried, because it cannot be read twice.",[1878,1894,1895,1896,1899],{},"A ",[23,1897,1898],{},"Retry-After"," header sets the wait. When it asks for more than a minute, the call is not retried.",[1878,1901,1902,1903,1905],{},"An aborted ",[23,1904,1225],{}," stops the wait and the retries.",[1878,1907,1908,1909,1911],{},"The request interceptors and the ",[23,1910,126],{}," resolver run once, so every retry sends the same headers.",[11,1913,1914,1915,1917,1918,222],{},"A streaming call uses the same ",[23,1916,148],{},", see ",[462,1919,1921],{"href":1920},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fplugin-fetch\u002Fguides\u002Fserver-sent-events#stop-abort-and-resume","Stop, abort, and resume",[15,1923,1925],{"id":1924},"less-common-cases","Less common cases",[1927,1928,489],"h3",{"id":1929},"which-server-a-call-picks",[11,1931,1932,1933,1935,1936,1942,1943,1945,1946,1949,1950,1953,1954,222],{},"When an operation or path has its own ",[23,1934,429],{},", the ",[462,1937,1939],{"href":1938},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fadapter-oas\u002Foptions#server",[23,1940,1941],{},"server.index"," of ",[23,1944,482],{}," picks the entry, falling back to the first. A relative URL such as ",[23,1947,1948],{},"\u002Fv2",", or one with ",[23,1951,1952],{},"{variable}"," placeholders, is skipped, so the call uses the next source in ",[462,1955,391],{"href":1956},"#set-the-base-url",[11,1958,460,1959,1963,1964,1967,1968,1970,1971,222],{},[462,1960,1961],{"href":464},[23,1962,121],{}," option is written into ",[23,1965,1966],{},".kubb\u002Fconfig.ts",", which ",[23,1969,29],{}," passes to ",[23,1972,226],{},[1927,1974,494],{"id":1975},"named-servers",[11,1977,1978,1979,70,1981,1983,1984,1263],{},"When an OpenAPI 3.2 server has a ",[23,1980,680],{},[23,1982,29],{}," exports its URL in ",[23,1985,429],{},[861,1987,1988,2050],{},[158,1989,1993],{"language":1990,"filename":1991,"code":1992,"class":162},"yaml","petStore.yaml","servers:\n - url: https:\u002F\u002Fapi.example.com\n name: production\n - url: https:\u002F\u002Fstaging.example.com\n name: staging",[23,1994,1996,197,2002,197,2014,197,2025,197,2039],{"class":1995},"language-yaml",[167,1997,1998,2000],{"class":169,"style":170},[167,1999,429],{"style":177},[167,2001,1263],{"style":173},[167,2003,2004,2007,2009,2011],{"class":169,"style":170},[167,2005,2006],{"style":173}," - ",[167,2008,1214],{"style":177},[167,2010,234],{"style":173},[167,2012,2013],{"style":195},"https:\u002F\u002Fapi.example.com",[167,2015,2016,2018,2020,2022],{"class":169,"style":170},[167,2017,1706],{"style":195},[167,2019,680],{"style":177},[167,2021,234],{"style":173},[167,2023,2024],{"style":195},"production",[167,2026,2027,2029,2032,2034,2036],{"class":169,"style":170},[167,2028,534],{"style":195},[167,2030,2031],{"style":173},"- ",[167,2033,1214],{"style":177},[167,2035,234],{"style":173},[167,2037,2038],{"style":195},"https:\u002F\u002Fstaging.example.com",[167,2040,2041,2043,2045,2047],{"class":169,"style":170},[167,2042,1706],{"style":195},[167,2044,680],{"style":177},[167,2046,234],{"style":173},[167,2048,2049],{"style":195},"staging",[158,2051,2054],{"language":160,"filename":2052,"code":2053,"class":162},"src\u002Fapi.ts","import { client, servers } from '.\u002Fgen\u002F.kubb\u002Fclient'\n\nclient.setConfig({ baseURL: servers.staging })",[23,2055,2056,197,2075,197,2077],{"class":165},[167,2057,2058,2060,2062,2064,2066,2069,2071,2073],{"class":169,"style":170},[167,2059,174],{"style":173},[167,2061,178],{"style":177},[167,2063,25],{"style":181},[167,2065,70],{"style":173},[167,2067,2068],{"style":181},"servers ",[167,2070,189],{"style":177},[167,2072,192],{"style":173},[167,2074,196],{"style":195},[167,2076],{"class":169,"style":170},[167,2078,2079,2081,2083,2085,2087,2089,2091,2093,2095,2098],{"class":169,"style":170},[167,2080,25],{"style":181},[167,2082,222],{"style":173},[167,2084,226],{"style":225},[167,2086,229],{"style":177},[167,2088,121],{"style":177},[167,2090,234],{"style":173},[167,2092,429],{"style":181},[167,2094,222],{"style":173},[167,2096,2097],{"style":177},"staging ",[167,2099,314],{"style":177},[1927,2101,766],{"id":2102},"several-security-schemes",[11,2104,2105,2106,2108,2109,2112,2113,2115],{},"When an operation lists several security requirements, the runtime sends the first one whose schemes all get a token. A requirement that needs an API key and a session cookie sends both. A header or query key you set yourself wins over the token. An ",[23,2107,723],{}," scheme also passes ",[23,2110,2111],{},"metadataUrl"," to ",[23,2114,126],{}," when the spec has one.",[11,2117,2118,2120,2121,2124],{},[23,2119,29],{}," exports the spec's schemes by name as ",[23,2122,2123],{},"securitySchemes",", and each generated call points at its own, with the scopes it needs:",[158,2126,2128],{"language":160,"code":2127,"class":162},"security: [{ ...securitySchemes.petstore_auth, scopes: ['write:pets'] }]",[23,2129,2130],{"class":165},[167,2131,2132,2135,2137,2140,2142,2144,2146,2149,2151,2154,2156,2158,2161],{"class":169,"style":170},[167,2133,2134],{"style":181},"security",[167,2136,234],{"style":173},[167,2138,2139],{"style":177},"[{ ",[167,2141,1339],{"style":173},[167,2143,2123],{"style":181},[167,2145,222],{"style":173},[167,2147,2148],{"style":177},"petstore_auth",[167,2150,70],{"style":173},[167,2152,2153],{"style":177},"scopes",[167,2155,234],{"style":173},[167,2157,910],{"style":177},[167,2159,2160],{"style":195},"'write:pets'",[167,2162,2163],{"style":177},"] }]",[1927,2165,770],{"id":2166},"mutual-tls",[11,2168,2169,2170,2173,2174,2176,2177,2180,2181,222],{},"When the spec has a ",[23,2171,2172],{},"mutualTLS"," scheme, ",[23,2175,2123],{}," leaves it out, because its credential is a client certificate on the connection, not on the request. In Node.js, send through an undici ",[23,2178,2179],{},"Agent"," that holds the certificate, with a ",[462,2182,2183],{"href":1409},"custom transport",[11,2185,2186],{},"In the browser, the browser picks the client certificate itself.",{"title":2188,"searchDepth":2189,"depth":2189,"links":2190},"",5,[2191,2193,2194,2195,2196,2197],{"id":17,"depth":2192,"text":18},2,{"id":390,"depth":2192,"text":391},{"id":497,"depth":2192,"text":498},{"id":773,"depth":2192,"text":774},{"id":1413,"depth":2192,"text":1414},{"id":1924,"depth":2192,"text":1925,"children":2198},[2199,2201,2202,2203],{"id":1929,"depth":2200,"text":489},3,{"id":1975,"depth":2200,"text":494},{"id":2102,"depth":2200,"text":766},{"id":2166,"depth":2200,"text":770},"\u002Fextensions\u002Fkubb-labs\u002Fplugin-fetch\u002Fguides\u002Fconfigure-requests",1795727684365,"1b64b1eb-29b7-4f90-ad41-6f24721e1669"]