Vite Request

screenshot of Vite Request

基于 axios 二次封装的请求库。登录态、错误请求重新尝试发起、loading、错误处理、重复请求拦截、取消请求、多域名、断网情况、错误信息的埋点统计

Overview

ViteRequest is an impressive request library built on top of Axios, designed to facilitate speedy application in various business contexts. Its secondary encapsulation approach allows developers to handle requests more effectively by centralizing their configuration and error management. With a set of flexible features tailored for modern web development needs, ViteRequest stands out in optimizing API interaction while maintaining clean and organized code.

What truly makes ViteRequest appealing is its comprehensive functionality that addresses common scenarios developers face in API requests. From managing authentication tokens to handling loading states and error processes, this library offers an intuitive and efficient way to streamline backend communication.

Features

  • Token Management: Automatically determines if requests need a token and can refresh expired tokens seamlessly, ensuring secure API interactions.
  • Retry Mechanism: Features a built-in retry system that attempts to resend failed requests up to three times, with customizable retry counts for robust error handling.
  • Loading State Control: Provides customizable loading indicators to enhance user experience, preventing multiple loading animations and managing display duration intelligently.
  • Unified Error Handling: Allows for a centralized approach to error management through custom error handling functions, making it easier to handle various error responses consistently.
  • Caching Capabilities: Implements in-memory caching for requests, returning cached results when available to improve performance and reduce server load.
  • Multi-Domain Support: Facilitates API requests across multiple domains by initializing different instances with varying base URLs, simplifying configuration in complex environments.
  • TypeScript Support: Built with TypeScript in mind, ensuring type safety and improving the development experience through better tooling and autocompletion.
  • Customizable Configuration: Offers extensive customization options through instance-specific settings, allowing developers to tailor requests to their specific needs with ease.
typescript
Typescript

TypeScript is a superset of JavaScript, providing optional static typing, classes, interfaces, and other features that help developers write more maintainable and scalable code. TypeScript's static typing system can catch errors at compile-time, making it easier to build and maintain large applications.