版博士V2.0程序
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313
  1. <h1 align="center">
  2. <b>
  3. <a href="https://axios-http.com"><img src="https://axios-http.com/assets/logo.svg" /></a><br>
  4. </b>
  5. </h1>
  6. <p align="center">Promise based HTTP client for the browser and node.js</p>
  7. <p align="center">
  8. <a href="https://axios-http.com/"><b>Website</b></a> •
  9. <a href="https://axios-http.com/docs/intro"><b>Documentation</b></a>
  10. </p>
  11. <div align="center">
  12. [![npm version](https://img.shields.io/npm/v/axios.svg?style=flat-square)](https://www.npmjs.org/package/axios)
  13. [![CDNJS](https://img.shields.io/cdnjs/v/axios.svg?style=flat-square)](https://cdnjs.com/libraries/axios)
  14. [![Build status](https://img.shields.io/github/actions/workflow/status/axios/axios/ci.yml?branch=v1.x&label=CI&logo=github&style=flat-square)](https://github.com/axios/axios/actions/workflows/ci.yml)
  15. [![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod&style=flat-square)](https://gitpod.io/#https://github.com/axios/axios)
  16. [![code coverage](https://img.shields.io/coveralls/mzabriskie/axios.svg?style=flat-square)](https://coveralls.io/r/mzabriskie/axios)
  17. [![install size](https://img.shields.io/badge/dynamic/json?url=https://packagephobia.com/v2/api.json?p=axios&query=$.install.pretty&label=install%20size&style=flat-square)](https://packagephobia.now.sh/result?p=axios)
  18. [![npm bundle size](https://img.shields.io/bundlephobia/minzip/axios?style=flat-square)](https://bundlephobia.com/package/axios@latest)
  19. [![npm downloads](https://img.shields.io/npm/dm/axios.svg?style=flat-square)](https://npm-stat.com/charts.html?package=axios)
  20. [![gitter chat](https://img.shields.io/gitter/room/mzabriskie/axios.svg?style=flat-square)](https://gitter.im/mzabriskie/axios)
  21. [![code helpers](https://www.codetriage.com/axios/axios/badges/users.svg)](https://www.codetriage.com/axios/axios)
  22. [![Known Vulnerabilities](https://snyk.io/test/npm/axios/badge.svg)](https://snyk.io/test/npm/axios)
  23. </div>
  24. ## Table of Contents
  25. - [Features](#features)
  26. - [Browser Support](#browser-support)
  27. - [Installing](#installing)
  28. - [Package manager](#package-manager)
  29. - [CDN](#cdn)
  30. - [Example](#example)
  31. - [Axios API](#axios-api)
  32. - [Request method aliases](#request-method-aliases)
  33. - [Concurrency 👎](#concurrency-deprecated)
  34. - [Creating an instance](#creating-an-instance)
  35. - [Instance methods](#instance-methods)
  36. - [Request Config](#request-config)
  37. - [Response Schema](#response-schema)
  38. - [Config Defaults](#config-defaults)
  39. - [Global axios defaults](#global-axios-defaults)
  40. - [Custom instance defaults](#custom-instance-defaults)
  41. - [Config order of precedence](#config-order-of-precedence)
  42. - [Interceptors](#interceptors)
  43. - [Multiple Interceptors](#multiple-interceptors)
  44. - [Handling Errors](#handling-errors)
  45. - [Cancellation](#cancellation)
  46. - [AbortController](#abortcontroller)
  47. - [CancelToken 👎](#canceltoken-deprecated)
  48. - [Using application/x-www-form-urlencoded format](#using-applicationx-www-form-urlencoded-format)
  49. - [URLSearchParams](#urlsearchparams)
  50. - [Query string](#query-string-older-browsers)
  51. - [🆕 Automatic serialization](#-automatic-serialization-to-urlsearchparams)
  52. - [Using multipart/form-data format](#using-multipartform-data-format)
  53. - [FormData](#formdata)
  54. - [🆕 Automatic serialization](#-automatic-serialization-to-formdata)
  55. - [Files Posting](#files-posting)
  56. - [HTML Form Posting](#-html-form-posting-browser)
  57. - [🆕 Progress capturing](#-progress-capturing)
  58. - [🆕 Rate limiting](#-progress-capturing)
  59. - [Semver](#semver)
  60. - [Promises](#promises)
  61. - [TypeScript](#typescript)
  62. - [Resources](#resources)
  63. - [Credits](#credits)
  64. - [License](#license)
  65. ## Features
  66. - Make [XMLHttpRequests](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) from the browser
  67. - Make [http](https://nodejs.org/api/http.html) requests from node.js
  68. - Supports the [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) API
  69. - Intercept request and response
  70. - Transform request and response data
  71. - Cancel requests
  72. - Automatic transforms for [JSON](https://www.json.org/json-en.html) data
  73. - 🆕 Automatic data object serialization to `multipart/form-data` and `x-www-form-urlencoded` body encodings
  74. - Client side support for protecting against [XSRF](https://en.wikipedia.org/wiki/Cross-site_request_forgery)
  75. ## Browser Support
  76. ![Chrome](https://raw.githubusercontent.com/alrra/browser-logos/main/src/chrome/chrome_48x48.png) | ![Firefox](https://raw.githubusercontent.com/alrra/browser-logos/main/src/firefox/firefox_48x48.png) | ![Safari](https://raw.githubusercontent.com/alrra/browser-logos/main/src/safari/safari_48x48.png) | ![Opera](https://raw.githubusercontent.com/alrra/browser-logos/main/src/opera/opera_48x48.png) | ![Edge](https://raw.githubusercontent.com/alrra/browser-logos/main/src/edge/edge_48x48.png) | ![IE](https://raw.githubusercontent.com/alrra/browser-logos/master/src/archive/internet-explorer_9-11/internet-explorer_9-11_48x48.png) |
  77. --- | --- | --- | --- | --- | --- |
  78. Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | 11 ✔ |
  79. [![Browser Matrix](https://saucelabs.com/open_sauce/build_matrix/axios.svg)](https://saucelabs.com/u/axios)
  80. ## Installing
  81. ### Package manager
  82. Using npm:
  83. ```bash
  84. $ npm install axios
  85. ```
  86. Using bower:
  87. ```bash
  88. $ bower install axios
  89. ```
  90. Using yarn:
  91. ```bash
  92. $ yarn add axios
  93. ```
  94. Using pnpm:
  95. ```bash
  96. $ pnpm add axios
  97. ```
  98. Once the package is installed, you can import the library using `import` or `require` approach:
  99. ```js
  100. import axios, {isCancel, AxiosError} from 'axios';
  101. ```
  102. You can also use the default export, since the named export is just a re-export from the Axios factory:
  103. ```js
  104. import axios from 'axios';
  105. console.log(axios.isCancel('something'));
  106. ````
  107. If you use `require` for importing, **only default export is available**:
  108. ```js
  109. const axios = require('axios');
  110. console.log(axios.isCancel('something'));
  111. ```
  112. For cases where something went wrong when trying to import a module into a custom or legacy environment,
  113. you can try importing the module package directly:
  114. ```js
  115. const axios = require('axios/dist/browser/axios.cjs'); // browser commonJS bundle (ES2017)
  116. // const axios = require('axios/dist/node/axios.cjs'); // node commonJS bundle (ES2017)
  117. ```
  118. ### CDN
  119. Using jsDelivr CDN (ES5 UMD browser module):
  120. ```html
  121. <script src="https://cdn.jsdelivr.net/npm/axios@1.1.2/dist/axios.min.js"></script>
  122. ```
  123. Using unpkg CDN:
  124. ```html
  125. <script src="https://unpkg.com/axios@1.1.2/dist/axios.min.js"></script>
  126. ```
  127. ## Example
  128. > **Note** CommonJS usage
  129. > In order to gain the TypeScript typings (for intellisense / autocomplete) while using CommonJS imports with `require()`, use the following approach:
  130. ```js
  131. import axios from 'axios';
  132. //const axios = require('axios'); // legacy way
  133. // Make a request for a user with a given ID
  134. axios.get('/user?ID=12345')
  135. .then(function (response) {
  136. // handle success
  137. console.log(response);
  138. })
  139. .catch(function (error) {
  140. // handle error
  141. console.log(error);
  142. })
  143. .finally(function () {
  144. // always executed
  145. });
  146. // Optionally the request above could also be done as
  147. axios.get('/user', {
  148. params: {
  149. ID: 12345
  150. }
  151. })
  152. .then(function (response) {
  153. console.log(response);
  154. })
  155. .catch(function (error) {
  156. console.log(error);
  157. })
  158. .finally(function () {
  159. // always executed
  160. });
  161. // Want to use async/await? Add the `async` keyword to your outer function/method.
  162. async function getUser() {
  163. try {
  164. const response = await axios.get('/user?ID=12345');
  165. console.log(response);
  166. } catch (error) {
  167. console.error(error);
  168. }
  169. }
  170. ```
  171. > **Note** `async/await` is part of ECMAScript 2017 and is not supported in Internet
  172. > Explorer and older browsers, so use with caution.
  173. Performing a `POST` request
  174. ```js
  175. axios.post('/user', {
  176. firstName: 'Fred',
  177. lastName: 'Flintstone'
  178. })
  179. .then(function (response) {
  180. console.log(response);
  181. })
  182. .catch(function (error) {
  183. console.log(error);
  184. });
  185. ```
  186. Performing multiple concurrent requests
  187. ```js
  188. function getUserAccount() {
  189. return axios.get('/user/12345');
  190. }
  191. function getUserPermissions() {
  192. return axios.get('/user/12345/permissions');
  193. }
  194. Promise.all([getUserAccount(), getUserPermissions()])
  195. .then(function (results) {
  196. const acct = results[0];
  197. const perm = results[1];
  198. });
  199. ```
  200. ## axios API
  201. Requests can be made by passing the relevant config to `axios`.
  202. ##### axios(config)
  203. ```js
  204. // Send a POST request
  205. axios({
  206. method: 'post',
  207. url: '/user/12345',
  208. data: {
  209. firstName: 'Fred',
  210. lastName: 'Flintstone'
  211. }
  212. });
  213. ```
  214. ```js
  215. // GET request for remote image in node.js
  216. axios({
  217. method: 'get',
  218. url: 'https://bit.ly/2mTM3nY',
  219. responseType: 'stream'
  220. })
  221. .then(function (response) {
  222. response.data.pipe(fs.createWriteStream('ada_lovelace.jpg'))
  223. });
  224. ```
  225. ##### axios(url[, config])
  226. ```js
  227. // Send a GET request (default method)
  228. axios('/user/12345');
  229. ```
  230. ### Request method aliases
  231. For convenience, aliases have been provided for all common request methods.
  232. ##### axios.request(config)
  233. ##### axios.get(url[, config])
  234. ##### axios.delete(url[, config])
  235. ##### axios.head(url[, config])
  236. ##### axios.options(url[, config])
  237. ##### axios.post(url[, data[, config]])
  238. ##### axios.put(url[, data[, config]])
  239. ##### axios.patch(url[, data[, config]])
  240. ###### NOTE
  241. When using the alias methods `url`, `method`, and `data` properties don't need to be specified in config.
  242. ### Concurrency (Deprecated)
  243. Please use `Promise.all` to replace the below functions.
  244. Helper functions for dealing with concurrent requests.
  245. axios.all(iterable)
  246. axios.spread(callback)
  247. ### Creating an instance
  248. You can create a new instance of axios with a custom config.
  249. ##### axios.create([config])
  250. ```js
  251. const instance = axios.create({
  252. baseURL: 'https://some-domain.com/api/',
  253. timeout: 1000,
  254. headers: {'X-Custom-Header': 'foobar'}
  255. });
  256. ```
  257. ### Instance methods
  258. The available instance methods are listed below. The specified config will be merged with the instance config.
  259. ##### axios#request(config)
  260. ##### axios#get(url[, config])
  261. ##### axios#delete(url[, config])
  262. ##### axios#head(url[, config])
  263. ##### axios#options(url[, config])
  264. ##### axios#post(url[, data[, config]])
  265. ##### axios#put(url[, data[, config]])
  266. ##### axios#patch(url[, data[, config]])
  267. ##### axios#getUri([config])
  268. ## Request Config
  269. These are the available config options for making requests. Only the `url` is required. Requests will default to `GET` if `method` is not specified.
  270. ```js
  271. {
  272. // `url` is the server URL that will be used for the request
  273. url: '/user',
  274. // `method` is the request method to be used when making the request
  275. method: 'get', // default
  276. // `baseURL` will be prepended to `url` unless `url` is absolute.
  277. // It can be convenient to set `baseURL` for an instance of axios to pass relative URLs
  278. // to methods of that instance.
  279. baseURL: 'https://some-domain.com/api/',
  280. // `transformRequest` allows changes to the request data before it is sent to the server
  281. // This is only applicable for request methods 'PUT', 'POST', 'PATCH' and 'DELETE'
  282. // The last function in the array must return a string or an instance of Buffer, ArrayBuffer,
  283. // FormData or Stream
  284. // You may modify the headers object.
  285. transformRequest: [function (data, headers) {
  286. // Do whatever you want to transform the data
  287. return data;
  288. }],
  289. // `transformResponse` allows changes to the response data to be made before
  290. // it is passed to then/catch
  291. transformResponse: [function (data) {
  292. // Do whatever you want to transform the data
  293. return data;
  294. }],
  295. // `headers` are custom headers to be sent
  296. headers: {'X-Requested-With': 'XMLHttpRequest'},
  297. // `params` are the URL parameters to be sent with the request
  298. // Must be a plain object or a URLSearchParams object
  299. params: {
  300. ID: 12345
  301. },
  302. // `paramsSerializer` is an optional config in charge of serializing `params`
  303. paramsSerializer: {
  304. encode?: (param: string): string => { /* Do custom ops here and return transformed string */ }, // custom encoder function; sends Key/Values in an iterative fashion
  305. serialize?: (params: Record<string, any>, options?: ParamsSerializerOptions ), // mimic pre 1.x behavior and send entire params object to a custom serializer func. Allows consumer to control how params are serialized.
  306. indexes: false // array indexes format (null - no brackets, false (default) - empty brackets, true - brackets with indexes)
  307. },
  308. // `data` is the data to be sent as the request body
  309. // Only applicable for request methods 'PUT', 'POST', 'DELETE , and 'PATCH'
  310. // When no `transformRequest` is set, must be of one of the following types:
  311. // - string, plain object, ArrayBuffer, ArrayBufferView, URLSearchParams
  312. // - Browser only: FormData, File, Blob
  313. // - Node only: Stream, Buffer, FormData (form-data package)
  314. data: {
  315. firstName: 'Fred'
  316. },
  317. // syntax alternative to send data into the body
  318. // method post
  319. // only the value is sent, not the key
  320. data: 'Country=Brasil&City=Belo Horizonte',
  321. // `timeout` specifies the number of milliseconds before the request times out.
  322. // If the request takes longer than `timeout`, the request will be aborted.
  323. timeout: 1000, // default is `0` (no timeout)
  324. // `withCredentials` indicates whether or not cross-site Access-Control requests
  325. // should be made using credentials
  326. withCredentials: false, // default
  327. // `adapter` allows custom handling of requests which makes testing easier.
  328. // Return a promise and supply a valid response (see lib/adapters/README.md).
  329. adapter: function (config) {
  330. /* ... */
  331. },
  332. // `auth` indicates that HTTP Basic auth should be used, and supplies credentials.
  333. // This will set an `Authorization` header, overwriting any existing
  334. // `Authorization` custom headers you have set using `headers`.
  335. // Please note that only HTTP Basic auth is configurable through this parameter.
  336. // For Bearer tokens and such, use `Authorization` custom headers instead.
  337. auth: {
  338. username: 'janedoe',
  339. password: 's00pers3cret'
  340. },
  341. // `responseType` indicates the type of data that the server will respond with
  342. // options are: 'arraybuffer', 'document', 'json', 'text', 'stream'
  343. // browser only: 'blob'
  344. responseType: 'json', // default
  345. // `responseEncoding` indicates encoding to use for decoding responses (Node.js only)
  346. // Note: Ignored for `responseType` of 'stream' or client-side requests
  347. responseEncoding: 'utf8', // default
  348. // `xsrfCookieName` is the name of the cookie to use as a value for xsrf token
  349. xsrfCookieName: 'XSRF-TOKEN', // default
  350. // `xsrfHeaderName` is the name of the http header that carries the xsrf token value
  351. xsrfHeaderName: 'X-XSRF-TOKEN', // default
  352. // `onUploadProgress` allows handling of progress events for uploads
  353. // browser & node.js
  354. onUploadProgress: function ({loaded, total, progress, bytes, estimated, rate, upload = true}) {
  355. // Do whatever you want with the Axios progress event
  356. },
  357. // `onDownloadProgress` allows handling of progress events for downloads
  358. // browser & node.js
  359. onDownloadProgress: function ({loaded, total, progress, bytes, estimated, rate, download = true}) {
  360. // Do whatever you want with the Axios progress event
  361. },
  362. // `maxContentLength` defines the max size of the http response content in bytes allowed in node.js
  363. maxContentLength: 2000,
  364. // `maxBodyLength` (Node only option) defines the max size of the http request content in bytes allowed
  365. maxBodyLength: 2000,
  366. // `validateStatus` defines whether to resolve or reject the promise for a given
  367. // HTTP response status code. If `validateStatus` returns `true` (or is set to `null`
  368. // or `undefined`), the promise will be resolved; otherwise, the promise will be
  369. // rejected.
  370. validateStatus: function (status) {
  371. return status >= 200 && status < 300; // default
  372. },
  373. // `maxRedirects` defines the maximum number of redirects to follow in node.js.
  374. // If set to 0, no redirects will be followed.
  375. maxRedirects: 21, // default
  376. // `beforeRedirect` defines a function that will be called before redirect.
  377. // Use this to adjust the request options upon redirecting,
  378. // to inspect the latest response headers,
  379. // or to cancel the request by throwing an error
  380. // If maxRedirects is set to 0, `beforeRedirect` is not used.
  381. beforeRedirect: (options, { headers }) => {
  382. if (options.hostname === "example.com") {
  383. options.auth = "user:password";
  384. }
  385. },
  386. // `socketPath` defines a UNIX Socket to be used in node.js.
  387. // e.g. '/var/run/docker.sock' to send requests to the docker daemon.
  388. // Only either `socketPath` or `proxy` can be specified.
  389. // If both are specified, `socketPath` is used.
  390. socketPath: null, // default
  391. // `transport` determines the transport method that will be used to make the request. If defined, it will be used. Otherwise, if `maxRedirects` is 0, the default `http` or `https` library will be used, depending on the protocol specified in `protocol`. Otherwise, the `httpFollow` or `httpsFollow` library will be used, again depending on the protocol, which can handle redirects.
  392. transport: undefined, // default
  393. // `httpAgent` and `httpsAgent` define a custom agent to be used when performing http
  394. // and https requests, respectively, in node.js. This allows options to be added like
  395. // `keepAlive` that are not enabled by default.
  396. httpAgent: new http.Agent({ keepAlive: true }),
  397. httpsAgent: new https.Agent({ keepAlive: true }),
  398. // `proxy` defines the hostname, port, and protocol of the proxy server.
  399. // You can also define your proxy using the conventional `http_proxy` and
  400. // `https_proxy` environment variables. If you are using environment variables
  401. // for your proxy configuration, you can also define a `no_proxy` environment
  402. // variable as a comma-separated list of domains that should not be proxied.
  403. // Use `false` to disable proxies, ignoring environment variables.
  404. // `auth` indicates that HTTP Basic auth should be used to connect to the proxy, and
  405. // supplies credentials.
  406. // This will set an `Proxy-Authorization` header, overwriting any existing
  407. // `Proxy-Authorization` custom headers you have set using `headers`.
  408. // If the proxy server uses HTTPS, then you must set the protocol to `https`.
  409. proxy: {
  410. protocol: 'https',
  411. host: '127.0.0.1',
  412. // hostname: '127.0.0.1' // Takes precedence over 'host' if both are defined
  413. port: 9000,
  414. auth: {
  415. username: 'mikeymike',
  416. password: 'rapunz3l'
  417. }
  418. },
  419. // `cancelToken` specifies a cancel token that can be used to cancel the request
  420. // (see Cancellation section below for details)
  421. cancelToken: new CancelToken(function (cancel) {
  422. }),
  423. // an alternative way to cancel Axios requests using AbortController
  424. signal: new AbortController().signal,
  425. // `decompress` indicates whether or not the response body should be decompressed
  426. // automatically. If set to `true` will also remove the 'content-encoding' header
  427. // from the responses objects of all decompressed responses
  428. // - Node only (XHR cannot turn off decompression)
  429. decompress: true // default
  430. // `insecureHTTPParser` boolean.
  431. // Indicates where to use an insecure HTTP parser that accepts invalid HTTP headers.
  432. // This may allow interoperability with non-conformant HTTP implementations.
  433. // Using the insecure parser should be avoided.
  434. // see options https://nodejs.org/dist/latest-v12.x/docs/api/http.html#http_http_request_url_options_callback
  435. // see also https://nodejs.org/en/blog/vulnerability/february-2020-security-releases/#strict-http-header-parsing-none
  436. insecureHTTPParser: undefined // default
  437. // transitional options for backward compatibility that may be removed in the newer versions
  438. transitional: {
  439. // silent JSON parsing mode
  440. // `true` - ignore JSON parsing errors and set response.data to null if parsing failed (old behaviour)
  441. // `false` - throw SyntaxError if JSON parsing failed (Note: responseType must be set to 'json')
  442. silentJSONParsing: true, // default value for the current Axios version
  443. // try to parse the response string as JSON even if `responseType` is not 'json'
  444. forcedJSONParsing: true,
  445. // throw ETIMEDOUT error instead of generic ECONNABORTED on request timeouts
  446. clarifyTimeoutError: false,
  447. },
  448. env: {
  449. // The FormData class to be used to automatically serialize the payload into a FormData object
  450. FormData: window?.FormData || global?.FormData
  451. },
  452. formSerializer: {
  453. visitor: (value, key, path, helpers) => {}; // custom visitor function to serialize form values
  454. dots: boolean; // use dots instead of brackets format
  455. metaTokens: boolean; // keep special endings like {} in parameter key
  456. indexes: boolean; // array indexes format null - no brackets, false - empty brackets, true - brackets with indexes
  457. },
  458. // http adapter only (node.js)
  459. maxRate: [
  460. 100 * 1024, // 100KB/s upload limit,
  461. 100 * 1024 // 100KB/s download limit
  462. ]
  463. }
  464. ```
  465. ## Response Schema
  466. The response for a request contains the following information.
  467. ```js
  468. {
  469. // `data` is the response that was provided by the server
  470. data: {},
  471. // `status` is the HTTP status code from the server response
  472. status: 200,
  473. // `statusText` is the HTTP status message from the server response
  474. statusText: 'OK',
  475. // `headers` the HTTP headers that the server responded with
  476. // All header names are lowercase and can be accessed using the bracket notation.
  477. // Example: `response.headers['content-type']`
  478. headers: {},
  479. // `config` is the config that was provided to `axios` for the request
  480. config: {},
  481. // `request` is the request that generated this response
  482. // It is the last ClientRequest instance in node.js (in redirects)
  483. // and an XMLHttpRequest instance in the browser
  484. request: {}
  485. }
  486. ```
  487. When using `then`, you will receive the response as follows:
  488. ```js
  489. axios.get('/user/12345')
  490. .then(function (response) {
  491. console.log(response.data);
  492. console.log(response.status);
  493. console.log(response.statusText);
  494. console.log(response.headers);
  495. console.log(response.config);
  496. });
  497. ```
  498. When using `catch`, or passing a [rejection callback](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then) as second parameter of `then`, the response will be available through the `error` object as explained in the [Handling Errors](#handling-errors) section.
  499. ## Config Defaults
  500. You can specify config defaults that will be applied to every request.
  501. ### Global axios defaults
  502. ```js
  503. axios.defaults.baseURL = 'https://api.example.com';
  504. // Important: If axios is used with multiple domains, the AUTH_TOKEN will be sent to all of them.
  505. // See below for an example using Custom instance defaults instead.
  506. axios.defaults.headers.common['Authorization'] = AUTH_TOKEN;
  507. axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
  508. ```
  509. ### Custom instance defaults
  510. ```js
  511. // Set config defaults when creating the instance
  512. const instance = axios.create({
  513. baseURL: 'https://api.example.com'
  514. });
  515. // Alter defaults after instance has been created
  516. instance.defaults.headers.common['Authorization'] = AUTH_TOKEN;
  517. ```
  518. ### Config order of precedence
  519. Config will be merged with an order of precedence. The order is library defaults found in [lib/defaults.js](https://github.com/axios/axios/blob/master/lib/defaults/index.js#L28), then `defaults` property of the instance, and finally `config` argument for the request. The latter will take precedence over the former. Here's an example.
  520. ```js
  521. // Create an instance using the config defaults provided by the library
  522. // At this point the timeout config value is `0` as is the default for the library
  523. const instance = axios.create();
  524. // Override timeout default for the library
  525. // Now all requests using this instance will wait 2.5 seconds before timing out
  526. instance.defaults.timeout = 2500;
  527. // Override timeout for this request as it's known to take a long time
  528. instance.get('/longRequest', {
  529. timeout: 5000
  530. });
  531. ```
  532. ## Interceptors
  533. You can intercept requests or responses before they are handled by `then` or `catch`.
  534. ```js
  535. // Add a request interceptor
  536. axios.interceptors.request.use(function (config) {
  537. // Do something before request is sent
  538. return config;
  539. }, function (error) {
  540. // Do something with request error
  541. return Promise.reject(error);
  542. });
  543. // Add a response interceptor
  544. axios.interceptors.response.use(function (response) {
  545. // Any status code that lie within the range of 2xx cause this function to trigger
  546. // Do something with response data
  547. return response;
  548. }, function (error) {
  549. // Any status codes that falls outside the range of 2xx cause this function to trigger
  550. // Do something with response error
  551. return Promise.reject(error);
  552. });
  553. ```
  554. If you need to remove an interceptor later you can.
  555. ```js
  556. const myInterceptor = axios.interceptors.request.use(function () {/*...*/});
  557. axios.interceptors.request.eject(myInterceptor);
  558. ```
  559. You can also clear all interceptors for requests or responses.
  560. ```js
  561. const instance = axios.create();
  562. instance.interceptors.request.use(function () {/*...*/});
  563. instance.interceptors.request.clear(); // Removes interceptors from requests
  564. instance.interceptors.response.use(function () {/*...*/});
  565. instance.interceptors.response.clear(); // Removes interceptors from responses
  566. ```
  567. You can add interceptors to a custom instance of axios.
  568. ```js
  569. const instance = axios.create();
  570. instance.interceptors.request.use(function () {/*...*/});
  571. ```
  572. When you add request interceptors, they are presumed to be asynchronous by default. This can cause a delay
  573. in the execution of your axios request when the main thread is blocked (a promise is created under the hood for
  574. the interceptor and your request gets put on the bottom of the call stack). If your request interceptors are synchronous you can add a flag
  575. to the options object that will tell axios to run the code synchronously and avoid any delays in request execution.
  576. ```js
  577. axios.interceptors.request.use(function (config) {
  578. config.headers.test = 'I am only a header!';
  579. return config;
  580. }, null, { synchronous: true });
  581. ```
  582. If you want to execute a particular interceptor based on a runtime check,
  583. you can add a `runWhen` function to the options object. The interceptor will not be executed **if and only if** the return
  584. of `runWhen` is `false`. The function will be called with the config
  585. object (don't forget that you can bind your own arguments to it as well.) This can be handy when you have an
  586. asynchronous request interceptor that only needs to run at certain times.
  587. ```js
  588. function onGetCall(config) {
  589. return config.method === 'get';
  590. }
  591. axios.interceptors.request.use(function (config) {
  592. config.headers.test = 'special get headers';
  593. return config;
  594. }, null, { runWhen: onGetCall });
  595. ```
  596. ### Multiple Interceptors
  597. Given you add multiple response interceptors
  598. and when the response was fulfilled
  599. - then each interceptor is executed
  600. - then they are executed in the order they were added
  601. - then only the last interceptor's result is returned
  602. - then every interceptor receives the result of its predecessor
  603. - and when the fulfillment-interceptor throws
  604. - then the following fulfillment-interceptor is not called
  605. - then the following rejection-interceptor is called
  606. - once caught, another following fulfill-interceptor is called again (just like in a promise chain).
  607. Read [the interceptor tests](./test/specs/interceptors.spec.js) for seeing all this in code.
  608. ## Handling Errors
  609. the default behavior is to reject every response that returns with a status code that falls out of the range of 2xx and treat it as an error.
  610. ```js
  611. axios.get('/user/12345')
  612. .catch(function (error) {
  613. if (error.response) {
  614. // The request was made and the server responded with a status code
  615. // that falls out of the range of 2xx
  616. console.log(error.response.data);
  617. console.log(error.response.status);
  618. console.log(error.response.headers);
  619. } else if (error.request) {
  620. // The request was made but no response was received
  621. // `error.request` is an instance of XMLHttpRequest in the browser and an instance of
  622. // http.ClientRequest in node.js
  623. console.log(error.request);
  624. } else {
  625. // Something happened in setting up the request that triggered an Error
  626. console.log('Error', error.message);
  627. }
  628. console.log(error.config);
  629. });
  630. ```
  631. Using the `validateStatus` config option, you can override the default condition (status >= 200 && status < 300) and define HTTP code(s) that should throw an error.
  632. ```js
  633. axios.get('/user/12345', {
  634. validateStatus: function (status) {
  635. return status < 500; // Resolve only if the status code is less than 500
  636. }
  637. })
  638. ```
  639. Using `toJSON` you get an object with more information about the HTTP error.
  640. ```js
  641. axios.get('/user/12345')
  642. .catch(function (error) {
  643. console.log(error.toJSON());
  644. });
  645. ```
  646. ## Cancellation
  647. ### AbortController
  648. Starting from `v0.22.0` Axios supports AbortController to cancel requests in fetch API way:
  649. ```js
  650. const controller = new AbortController();
  651. axios.get('/foo/bar', {
  652. signal: controller.signal
  653. }).then(function(response) {
  654. //...
  655. });
  656. // cancel the request
  657. controller.abort()
  658. ```
  659. ### CancelToken `👎deprecated`
  660. You can also cancel a request using a *CancelToken*.
  661. > The axios cancel token API is based on the withdrawn [cancellable promises proposal](https://github.com/tc39/proposal-cancelable-promises).
  662. > This API is deprecated since v0.22.0 and shouldn't be used in new projects
  663. You can create a cancel token using the `CancelToken.source` factory as shown below:
  664. ```js
  665. const CancelToken = axios.CancelToken;
  666. const source = CancelToken.source();
  667. axios.get('/user/12345', {
  668. cancelToken: source.token
  669. }).catch(function (thrown) {
  670. if (axios.isCancel(thrown)) {
  671. console.log('Request canceled', thrown.message);
  672. } else {
  673. // handle error
  674. }
  675. });
  676. axios.post('/user/12345', {
  677. name: 'new name'
  678. }, {
  679. cancelToken: source.token
  680. })
  681. // cancel the request (the message parameter is optional)
  682. source.cancel('Operation canceled by the user.');
  683. ```
  684. You can also create a cancel token by passing an executor function to the `CancelToken` constructor:
  685. ```js
  686. const CancelToken = axios.CancelToken;
  687. let cancel;
  688. axios.get('/user/12345', {
  689. cancelToken: new CancelToken(function executor(c) {
  690. // An executor function receives a cancel function as a parameter
  691. cancel = c;
  692. })
  693. });
  694. // cancel the request
  695. cancel();
  696. ```
  697. > **Note:** you can cancel several requests with the same cancel token/abort controller.
  698. > If a cancellation token is already cancelled at the moment of starting an Axios request, then the request is cancelled immediately, without any attempts to make a real request.
  699. > During the transition period, you can use both cancellation APIs, even for the same request:
  700. ## Using `application/x-www-form-urlencoded` format
  701. ### URLSearchParams
  702. By default, axios serializes JavaScript objects to `JSON`. To send data in the [`application/x-www-form-urlencoded` format](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST) instead, you can use the [`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) API, which is [supported](http://www.caniuse.com/#feat=urlsearchparams) in the vast majority of browsers,and [ Node](https://nodejs.org/api/url.html#url_class_urlsearchparams) starting with v10 (released in 2018).
  703. ```js
  704. const params = new URLSearchParams({ foo: 'bar' });
  705. params.append('extraparam', 'value');
  706. axios.post('/foo', params);
  707. ```
  708. ### Query string (Older browsers)
  709. For compatibility with very old browsers, there is a [polyfill](https://github.com/WebReflection/url-search-params) available (make sure to polyfill the global environment).
  710. Alternatively, you can encode data using the [`qs`](https://github.com/ljharb/qs) library:
  711. ```js
  712. const qs = require('qs');
  713. axios.post('/foo', qs.stringify({ 'bar': 123 }));
  714. ```
  715. Or in another way (ES6),
  716. ```js
  717. import qs from 'qs';
  718. const data = { 'bar': 123 };
  719. const options = {
  720. method: 'POST',
  721. headers: { 'content-type': 'application/x-www-form-urlencoded' },
  722. data: qs.stringify(data),
  723. url,
  724. };
  725. axios(options);
  726. ```
  727. ### Older Node.js versions
  728. For older Node.js engines, you can use the [`querystring`](https://nodejs.org/api/querystring.html) module as follows:
  729. ```js
  730. const querystring = require('querystring');
  731. axios.post('https://something.com/', querystring.stringify({ foo: 'bar' }));
  732. ```
  733. You can also use the [`qs`](https://github.com/ljharb/qs) library.
  734. > **Note**
  735. > The `qs` library is preferable if you need to stringify nested objects, as the `querystring` method has [known issues](https://github.com/nodejs/node-v0.x-archive/issues/1665) with that use case.
  736. ### 🆕 Automatic serialization to URLSearchParams
  737. Axios will automatically serialize the data object to urlencoded format if the content-type header is set to "application/x-www-form-urlencoded".
  738. ```js
  739. const data = {
  740. x: 1,
  741. arr: [1, 2, 3],
  742. arr2: [1, [2], 3],
  743. users: [{name: 'Peter', surname: 'Griffin'}, {name: 'Thomas', surname: 'Anderson'}],
  744. };
  745. await axios.postForm('https://postman-echo.com/post', data,
  746. {headers: {'content-type': 'application/x-www-form-urlencoded'}}
  747. );
  748. ```
  749. The server will handle it as:
  750. ```js
  751. {
  752. x: '1',
  753. 'arr[]': [ '1', '2', '3' ],
  754. 'arr2[0]': '1',
  755. 'arr2[1][0]': '2',
  756. 'arr2[2]': '3',
  757. 'arr3[]': [ '1', '2', '3' ],
  758. 'users[0][name]': 'Peter',
  759. 'users[0][surname]': 'griffin',
  760. 'users[1][name]': 'Thomas',
  761. 'users[1][surname]': 'Anderson'
  762. }
  763. ````
  764. If your backend body-parser (like `body-parser` of `express.js`) supports nested objects decoding, you will get the same object on the server-side automatically
  765. ```js
  766. var app = express();
  767. app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies
  768. app.post('/', function (req, res, next) {
  769. // echo body as JSON
  770. res.send(JSON.stringify(req.body));
  771. });
  772. server = app.listen(3000);
  773. ```
  774. ## Using `multipart/form-data` format
  775. ### FormData
  776. To send the data as a `multipart/formdata` you need to pass a formData instance as a payload.
  777. Setting the `Content-Type` header is not required as Axios guesses it based on the payload type.
  778. ```js
  779. const formData = new FormData();
  780. formData.append('foo', 'bar');
  781. axios.post('https://httpbin.org/post', formData);
  782. ```
  783. In node.js, you can use the [`form-data`](https://github.com/form-data/form-data) library as follows:
  784. ```js
  785. const FormData = require('form-data');
  786. const form = new FormData();
  787. form.append('my_field', 'my value');
  788. form.append('my_buffer', new Buffer(10));
  789. form.append('my_file', fs.createReadStream('/foo/bar.jpg'));
  790. axios.post('https://example.com', form)
  791. ```
  792. ### 🆕 Automatic serialization to FormData
  793. Starting from `v0.27.0`, Axios supports automatic object serialization to a FormData object if the request `Content-Type`
  794. header is set to `multipart/form-data`.
  795. The following request will submit the data in a FormData format (Browser & Node.js):
  796. ```js
  797. import axios from 'axios';
  798. axios.post('https://httpbin.org/post', {x: 1}, {
  799. headers: {
  800. 'Content-Type': 'multipart/form-data'
  801. }
  802. }).then(({data}) => console.log(data));
  803. ```
  804. In the `node.js` build, the ([`form-data`](https://github.com/form-data/form-data)) polyfill is used by default.
  805. You can overload the FormData class by setting the `env.FormData` config variable,
  806. but you probably won't need it in most cases:
  807. ```js
  808. const axios = require('axios');
  809. var FormData = require('form-data');
  810. axios.post('https://httpbin.org/post', {x: 1, buf: new Buffer(10)}, {
  811. headers: {
  812. 'Content-Type': 'multipart/form-data'
  813. }
  814. }).then(({data}) => console.log(data));
  815. ```
  816. Axios FormData serializer supports some special endings to perform the following operations:
  817. - `{}` - serialize the value with JSON.stringify
  818. - `[]` - unwrap the array-like object as separate fields with the same key
  819. > **Note**
  820. > unwrap/expand operation will be used by default on arrays and FileList objects
  821. FormData serializer supports additional options via `config.formSerializer: object` property to handle rare cases:
  822. - `visitor: Function` - user-defined visitor function that will be called recursively to serialize the data object
  823. to a `FormData` object by following custom rules.
  824. - `dots: boolean = false` - use dot notation instead of brackets to serialize arrays and objects;
  825. - `metaTokens: boolean = true` - add the special ending (e.g `user{}: '{"name": "John"}'`) in the FormData key.
  826. The back-end body-parser could potentially use this meta-information to automatically parse the value as JSON.
  827. - `indexes: null|false|true = false` - controls how indexes will be added to unwrapped keys of `flat` array-like objects
  828. - `null` - don't add brackets (`arr: 1`, `arr: 2`, `arr: 3`)
  829. - `false`(default) - add empty brackets (`arr[]: 1`, `arr[]: 2`, `arr[]: 3`)
  830. - `true` - add brackets with indexes (`arr[0]: 1`, `arr[1]: 2`, `arr[2]: 3`)
  831. Let's say we have an object like this one:
  832. ```js
  833. const obj = {
  834. x: 1,
  835. arr: [1, 2, 3],
  836. arr2: [1, [2], 3],
  837. users: [{name: 'Peter', surname: 'Griffin'}, {name: 'Thomas', surname: 'Anderson'}],
  838. 'obj2{}': [{x:1}]
  839. };
  840. ```
  841. The following steps will be executed by the Axios serializer internally:
  842. ```js
  843. const formData = new FormData();
  844. formData.append('x', '1');
  845. formData.append('arr[]', '1');
  846. formData.append('arr[]', '2');
  847. formData.append('arr[]', '3');
  848. formData.append('arr2[0]', '1');
  849. formData.append('arr2[1][0]', '2');
  850. formData.append('arr2[2]', '3');
  851. formData.append('users[0][name]', 'Peter');
  852. formData.append('users[0][surname]', 'Griffin');
  853. formData.append('users[1][name]', 'Thomas');
  854. formData.append('users[1][surname]', 'Anderson');
  855. formData.append('obj2{}', '[{"x":1}]');
  856. ```
  857. Axios supports the following shortcut methods: `postForm`, `putForm`, `patchForm`
  858. which are just the corresponding http methods with the `Content-Type` header preset to `multipart/form-data`.
  859. ## Files Posting
  860. You can easily submit a single file:
  861. ```js
  862. await axios.postForm('https://httpbin.org/post', {
  863. 'myVar' : 'foo',
  864. 'file': document.querySelector('#fileInput').files[0]
  865. });
  866. ```
  867. or multiple files as `multipart/form-data`:
  868. ```js
  869. await axios.postForm('https://httpbin.org/post', {
  870. 'files[]': document.querySelector('#fileInput').files
  871. });
  872. ```
  873. `FileList` object can be passed directly:
  874. ```js
  875. await axios.postForm('https://httpbin.org/post', document.querySelector('#fileInput').files)
  876. ```
  877. All files will be sent with the same field names: `files[]`.
  878. ## 🆕 HTML Form Posting (browser)
  879. Pass HTML Form element as a payload to submit it as `multipart/form-data` content.
  880. ```js
  881. await axios.postForm('https://httpbin.org/post', document.querySelector('#htmlForm'));
  882. ```
  883. `FormData` and `HTMLForm` objects can also be posted as `JSON` by explicitly setting the `Content-Type` header to `application/json`:
  884. ```js
  885. await axios.post('https://httpbin.org/post', document.querySelector('#htmlForm'), {
  886. headers: {
  887. 'Content-Type': 'application/json'
  888. }
  889. })
  890. ```
  891. For example, the Form
  892. ```html
  893. <form id="form">
  894. <input type="text" name="foo" value="1">
  895. <input type="text" name="deep.prop" value="2">
  896. <input type="text" name="deep prop spaced" value="3">
  897. <input type="text" name="baz" value="4">
  898. <input type="text" name="baz" value="5">
  899. <select name="user.age">
  900. <option value="value1">Value 1</option>
  901. <option value="value2" selected>Value 2</option>
  902. <option value="value3">Value 3</option>
  903. </select>
  904. <input type="submit" value="Save">
  905. </form>
  906. ```
  907. will be submitted as the following JSON object:
  908. ```js
  909. {
  910. "foo": "1",
  911. "deep": {
  912. "prop": {
  913. "spaced": "3"
  914. }
  915. },
  916. "baz": [
  917. "4",
  918. "5"
  919. ],
  920. "user": {
  921. "age": "value2"
  922. }
  923. }
  924. ````
  925. Sending `Blobs`/`Files` as JSON (`base64`) is not currently supported.
  926. ## 🆕 Progress capturing
  927. Axios supports both browser and node environments to capture request upload/download progress.
  928. ```js
  929. await axios.post(url, data, {
  930. onUploadProgress: function (axiosProgressEvent) {
  931. /*{
  932. loaded: number;
  933. total?: number;
  934. progress?: number; // in range [0..1]
  935. bytes: number; // how many bytes have been transferred since the last trigger (delta)
  936. estimated?: number; // estimated time in seconds
  937. rate?: number; // upload speed in bytes
  938. upload: true; // upload sign
  939. }*/
  940. },
  941. onDownloadProgress: function (axiosProgressEvent) {
  942. /*{
  943. loaded: number;
  944. total?: number;
  945. progress?: number;
  946. bytes: number;
  947. estimated?: number;
  948. rate?: number; // download speed in bytes
  949. download: true; // download sign
  950. }*/
  951. }
  952. });
  953. ```
  954. You can also track stream upload/download progress in node.js:
  955. ```js
  956. const {data} = await axios.post(SERVER_URL, readableStream, {
  957. onUploadProgress: ({progress}) => {
  958. console.log((progress * 100).toFixed(2));
  959. },
  960. headers: {
  961. 'Content-Length': contentLength
  962. },
  963. maxRedirects: 0 // avoid buffering the entire stream
  964. });
  965. ````
  966. > **Note:**
  967. > Capturing FormData upload progress is currently not currently supported in node.js environments.
  968. > **⚠️ Warning**
  969. > It is recommended to disable redirects by setting maxRedirects: 0 to upload the stream in the **node.js** environment,
  970. > as follow-redirects package will buffer the entire stream in RAM without following the "backpressure" algorithm.
  971. ## 🆕 Rate limiting
  972. Download and upload rate limits can only be set for the http adapter (node.js):
  973. ```js
  974. const {data} = await axios.post(LOCAL_SERVER_URL, myBuffer, {
  975. onUploadProgress: ({progress, rate}) => {
  976. console.log(`Upload [${(progress*100).toFixed(2)}%]: ${(rate / 1024).toFixed(2)}KB/s`)
  977. },
  978. maxRate: [100 * 1024], // 100KB/s limit
  979. });
  980. ```
  981. ## Semver
  982. Until axios reaches a `1.0` release, breaking changes will be released with a new minor version. For example `0.5.1`, and `0.5.4` will have the same API, but `0.6.0` will have breaking changes.
  983. ## Promises
  984. axios depends on a native ES6 Promise implementation to be [supported](https://caniuse.com/promises).
  985. If your environment doesn't support ES6 Promises, you can [polyfill](https://github.com/jakearchibald/es6-promise).
  986. ## TypeScript
  987. axios includes [TypeScript](https://typescriptlang.org) definitions and a type guard for axios errors.
  988. ```typescript
  989. let user: User = null;
  990. try {
  991. const { data } = await axios.get('/user?ID=12345');
  992. user = data.userDetails;
  993. } catch (error) {
  994. if (axios.isAxiosError(error)) {
  995. handleAxiosError(error);
  996. } else {
  997. handleUnexpectedError(error);
  998. }
  999. }
  1000. ```
  1001. Because axios dual publishes with an ESM default export and a CJS `module.exports`, there are some caveats.
  1002. The recommended setting is to use `"moduleResolution": "node16"` (this is implied by `"module": "node16"`). Note that this requires TypeScript 4.7 or greater.
  1003. If use ESM, your settings should be fine.
  1004. If you compile TypeScript to CJS and you can’t use `"moduleResolution": "node 16"`, you have to enable `esModuleInterop`.
  1005. If you use TypeScript to type check CJS JavaScript code, your only option is to use `"moduleResolution": "node16"`.
  1006. ## Online one-click setup
  1007. You can use Gitpod, an online IDE(which is free for Open Source) for contributing or running the examples online.
  1008. [![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/axios/axios/blob/main/examples/server.js)
  1009. ## Resources
  1010. * [Changelog](https://github.com/axios/axios/blob/v1.x/CHANGELOG.md)
  1011. * [Ecosystem](https://github.com/axios/axios/blob/v1.x/ECOSYSTEM.md)
  1012. * [Contributing Guide](https://github.com/axios/axios/blob/v1.x/CONTRIBUTING.md)
  1013. * [Code of Conduct](https://github.com/axios/axios/blob/v1.x/CODE_OF_CONDUCT.md)
  1014. ## Credits
  1015. axios is heavily inspired by the [$http service](https://docs.angularjs.org/api/ng/service/$http) provided in [AngularJS](https://angularjs.org/). Ultimately axios is an effort to provide a standalone `$http`-like service for use outside of AngularJS.
  1016. ## License
  1017. [MIT](LICENSE)