Axios
content
- main idea
- interceptor
- Cancel
-
Promise: Axios' use of Promises is quite extreme
- Use the then chain to concatenate your ownrequest interceptor => ask => response interceptorchain, and then execute in an orderly manner
- Use the asynchronous idea of Promise, separate the resolve method, and provide the ability to actively cancel the request to the outside world
other
- Packaging of xhr/http: headers(Authorization: btoa/atob), buildFullPath, onloadend/onabort/onerror/ontimeout/progress
- enhanceError: Usually js has less abnormal error information, and Axios itself encapsulates more information for isAxiosError errors. You can get more HTTP error information through toJSON
- Utility functions: small and beautiful, named
- Conversion of request and response body: We do not need to deal with the Content-Type of the request body and the data format of the return body in most scenarios, but also allow developers to customize
- AbortController: Provides developers with a custom controller that blocks requests, similar to fetch(url, { signal })
Original illustration, reprinted remarks.