[{"data":1,"prerenderedAt":557},["ShallowReactive",2],{"page:\u002Fextensions\u002Fkubb-labs\u002Fplugin-axios\u002Fguides\u002Ftransport":3},{"id":4,"frontmatter":5,"title":6,"heading":6,"body":7,"path":556,"source":4},"extensions\u002Fkubb-labs\u002Fplugin-axios\u002Fguides\u002Ftransport.md",{},"Use a custom transport",{"type":8,"value":9,"toc":548},"minimark",[10,14,30,87,90,95,98,356,370,403,407,413,520,530,534],[11,12,13],"p",{},"Set a transport at runtime to replace the network send. The client still builds URLs, serializes parameters, resolves authentication, and handles results.",[11,15,16,17,21,22,25,26,29],{},"The transport is an ",[18,19,20],"code",{},"AxiosInstance",". The default is ",[18,23,24],{},"defaultTransport",", an ",[18,27,28],{},"axios.create()"," instance exported from the generated client, and you can replace it with your own pre-configured instance. Use interceptors for request headers or response logging.",[31,32,36],"pre",{"language":33,"code":34,"class":35},"typescript","type ClientConfig = {\n  \u002F\u002F ...\n  transport?: AxiosInstance\n}","highlights",[18,37,39,59,60,59,69,59,82],{"class":38},"language-typescript",[40,41,44,48,52,55],"span",{"class":42,"style":43},"line","display: inline",[40,45,47],{"style":46},"color:#d73a49;--hls-dark:#f97583","type ",[40,49,51],{"style":50},"color:#6f42c1;--hls-dark:#b392f0","ClientConfig ",[40,53,54],{"style":46},"= ",[40,56,58],{"style":57},"color:#005cc5;--hls-dark:#79b8ff","{","\n",[40,61,62,65],{"class":42,"style":43},[40,63,64],{"style":57},"  ",[40,66,68],{"style":67},"color:#6a737d;--hls-dark:#6a737d","\u002F\u002F ...",[40,70,71,73,76,80],{"class":42,"style":43},[40,72,64],{"style":67},[40,74,75],{"style":57},"transport",[40,77,79],{"style":78},"color:#24292e;--hls-dark:#e1e4e8","?: ",[40,81,20],{"style":50},[40,83,84],{"class":42,"style":43},[40,85,86],{"style":57},"}",[11,88,89],{},"Kubb forwards the resolved URL, query, body, and authentication to the instance.",[91,92,94],"h2",{"id":93},"pass-a-pre-configured-instance","Pass a pre-configured instance",[11,96,97],{},"Give the client an instance with a timeout, default headers, and a logging interceptor:",[31,99,101],{"language":33,"code":100,"class":35},"import axios from 'axios'\nimport { client } from '.\u002Fgen\u002F.kubb\u002Fclient'\n\nconst instance = axios.create({\n  timeout: 10_000,\n  headers: { 'X-Client': 'kubb' },\n})\n\ninstance.interceptors.response.use((response) => {\n  console.info(`${response.config.method?.toUpperCase()} ${response.config.url} -> ${response.status}`)\n  return response\n})\n\nclient.setConfig({ transport: instance })",[18,102,103,59,118,59,136,59,138,59,160,59,176,59,199,59,204,59,206,59,239,59,320,59,329,59,333,59,335],{"class":38},[40,104,105,108,111,114],{"class":42,"style":43},[40,106,107],{"style":46},"import ",[40,109,110],{"style":78},"axios ",[40,112,113],{"style":46},"from ",[40,115,117],{"style":116},"color:#032f62;--hls-dark:#9ecbff","'axios'",[40,119,120,122,125,128,131,133],{"class":42,"style":43},[40,121,107],{"style":46},[40,123,124],{"style":57},"{ ",[40,126,127],{"style":78},"client ",[40,129,130],{"style":57},"} ",[40,132,113],{"style":46},[40,134,135],{"style":116},"'.\u002Fgen\u002F.kubb\u002Fclient'",[40,137],{"class":42,"style":43},[40,139,140,143,146,148,151,154,157],{"class":42,"style":43},[40,141,142],{"style":46},"const ",[40,144,145],{"style":78},"instance ",[40,147,54],{"style":46},[40,149,150],{"style":78},"axios",[40,152,153],{"style":46},".",[40,155,156],{"style":50},"create",[40,158,159],{"style":57},"({",[40,161,162,164,167,170,173],{"class":42,"style":43},[40,163,64],{"style":57},[40,165,166],{"style":57},"timeout",[40,168,169],{"style":46},": ",[40,171,172],{"style":57},"10_000",[40,174,175],{"style":46},",",[40,177,178,180,183,185,187,190,192,195,197],{"class":42,"style":43},[40,179,64],{"style":46},[40,181,182],{"style":57},"headers",[40,184,169],{"style":46},[40,186,124],{"style":57},[40,188,189],{"style":116},"'X-Client'",[40,191,169],{"style":46},[40,193,194],{"style":116},"'kubb' ",[40,196,86],{"style":57},[40,198,175],{"style":46},[40,200,201],{"class":42,"style":43},[40,202,203],{"style":57},"})",[40,205],{"class":42,"style":43},[40,207,208,211,213,216,218,221,223,226,229,231,234,237],{"class":42,"style":43},[40,209,210],{"style":78},"instance",[40,212,153],{"style":46},[40,214,215],{"style":57},"interceptors",[40,217,153],{"style":46},[40,219,220],{"style":57},"response",[40,222,153],{"style":46},[40,224,225],{"style":50},"use",[40,227,228],{"style":57},"((",[40,230,220],{"style":78},[40,232,233],{"style":57},") ",[40,235,236],{"style":46},"=> ",[40,238,58],{"style":57},[40,240,241,243,246,248,251,254,257,260,262,264,267,269,272,275,278,281,283,286,288,290,292,294,296,299,301,304,306,308,310,313,315,317],{"class":42,"style":43},[40,242,64],{"style":57},[40,244,245],{"style":78},"console",[40,247,153],{"style":46},[40,249,250],{"style":50},"info",[40,252,253],{"style":57},"(",[40,255,256],{"style":116},"`",[40,258,259],{"style":78},"${",[40,261,220],{"style":78},[40,263,153],{"style":46},[40,265,266],{"style":57},"config",[40,268,153],{"style":46},[40,270,271],{"style":57},"method",[40,273,274],{"style":46},"?.",[40,276,277],{"style":50},"toUpperCase",[40,279,280],{"style":57},"()",[40,282,86],{"style":78},[40,284,285],{"style":116}," ",[40,287,259],{"style":78},[40,289,220],{"style":78},[40,291,153],{"style":46},[40,293,266],{"style":57},[40,295,153],{"style":46},[40,297,298],{"style":57},"url",[40,300,86],{"style":78},[40,302,303],{"style":116}," -> ",[40,305,259],{"style":78},[40,307,220],{"style":78},[40,309,153],{"style":46},[40,311,312],{"style":57},"status",[40,314,86],{"style":78},[40,316,256],{"style":116},[40,318,319],{"style":57},")",[40,321,322,324,327],{"class":42,"style":43},[40,323,64],{"style":57},[40,325,326],{"style":46},"return ",[40,328,220],{"style":78},[40,330,331],{"class":42,"style":43},[40,332,203],{"style":57},[40,334],{"class":42,"style":43},[40,336,337,340,342,345,348,350,352,354],{"class":42,"style":43},[40,338,339],{"style":78},"client",[40,341,153],{"style":46},[40,343,344],{"style":50},"setConfig",[40,346,347],{"style":57},"({ ",[40,349,75],{"style":57},[40,351,169],{"style":46},[40,353,145],{"style":78},[40,355,203],{"style":57},[11,357,358,359,362,363,366,367,153],{},"Every generated function now sends through your instance, so its timeout, headers, and interceptors apply to each call. Interceptors registered through ",[18,360,361],{},"client.interceptors"," move to the new instance and keep their IDs for ",[18,364,365],{},"eject"," and ",[18,368,369],{},"update",[371,372,374,375,378,379,382,383,386,387,390,391,394,395,398,399,402],"blockquote",{"as":373},"note","Kubb sets ",[18,376,377],{},"transformRequest",", ",[18,380,381],{},"paramsSerializer",", and ",[18,384,385],{},"validateStatus"," on each request for its own serialization and ",[18,388,389],{},"throwOnError"," handling, so leave those fields alone. Set timeouts, retries, and interceptors on the instance. For one call, pass ",[18,392,393],{},"options",", such as ",[18,396,397],{},"{ timeout }"," or ",[18,400,401],{},"{ onUploadProgress }",", instead of building a new instance.",[91,404,406],{"id":405},"use-the-default-instance","Use the default instance",[11,408,409,410,412],{},"The generated client exports ",[18,411,24],{},", the instance it sends through when no transport is set. Configure it directly to add tracing or headers without replacing the transport:",[31,414,416],{"language":33,"code":415,"class":35},"import { defaultTransport } from '.\u002Fgen\u002F.kubb\u002Fclient'\n\ndefaultTransport.defaults.timeout = 10_000\ndefaultTransport.interceptors.request.use((config) => {\n  config.headers.set('traceparent', currentTraceparent())\n  return config\n})",[18,417,418,59,433,59,435,59,453,59,480,59,508,59,516],{"class":38},[40,419,420,422,424,427,429,431],{"class":42,"style":43},[40,421,107],{"style":46},[40,423,124],{"style":57},[40,425,426],{"style":78},"defaultTransport ",[40,428,130],{"style":57},[40,430,113],{"style":46},[40,432,135],{"style":116},[40,434],{"class":42,"style":43},[40,436,437,439,441,444,446,449,451],{"class":42,"style":43},[40,438,24],{"style":78},[40,440,153],{"style":46},[40,442,443],{"style":57},"defaults",[40,445,153],{"style":46},[40,447,448],{"style":57},"timeout ",[40,450,54],{"style":46},[40,452,172],{"style":57},[40,454,455,457,459,461,463,466,468,470,472,474,476,478],{"class":42,"style":43},[40,456,24],{"style":78},[40,458,153],{"style":46},[40,460,215],{"style":57},[40,462,153],{"style":46},[40,464,465],{"style":57},"request",[40,467,153],{"style":46},[40,469,225],{"style":50},[40,471,228],{"style":57},[40,473,266],{"style":78},[40,475,233],{"style":57},[40,477,236],{"style":46},[40,479,58],{"style":57},[40,481,482,484,486,488,490,492,495,497,500,502,505],{"class":42,"style":43},[40,483,64],{"style":57},[40,485,266],{"style":78},[40,487,153],{"style":46},[40,489,182],{"style":57},[40,491,153],{"style":46},[40,493,494],{"style":50},"set",[40,496,253],{"style":57},[40,498,499],{"style":116},"'traceparent'",[40,501,378],{"style":46},[40,503,504],{"style":50},"currentTraceparent",[40,506,507],{"style":57},"())",[40,509,510,512,514],{"class":42,"style":43},[40,511,64],{"style":57},[40,513,326],{"style":46},[40,515,266],{"style":78},[40,517,518],{"class":42,"style":43},[40,519,203],{"style":57},[11,521,522,523,526,527,529],{},"Instances from ",[18,524,525],{},"createClient()"," get their own ",[18,528,28],{}," and do not share these settings.",[91,531,533],{"id":532},"where-to-set-it","Where to set it",[11,535,536,537,540,541,544,545,547],{},"Use ",[18,538,539],{},"client.setConfig({ transport })"," for shared configuration, ",[18,542,543],{},"createClient({ transport })"," for an isolated instance, or pass ",[18,546,75],{}," on an operation to override it for one call.",{"title":549,"searchDepth":550,"depth":550,"links":551},"",5,[552,554,555],{"id":93,"depth":553,"text":94},2,{"id":405,"depth":553,"text":406},{"id":532,"depth":553,"text":533},"\u002Fextensions\u002Fkubb-labs\u002Fplugin-axios\u002Fguides\u002Ftransport",1793639047164]