New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ts-x-request-pool

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-x-request-pool

> >Http的前端请求池,避免重复的请求。 > >使用单例模式,相同的请求会只发送一次,其余的则等待同请求返回后,再返回。 > > [Demo](https://mikexia930.github.io/xRequestPool/) ## 版本 - v1.1.0

  • 1.1.1
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

x-request-pool@ts

Http的前端请求池,避免重复的请求。

使用单例模式,相同的请求会只发送一次,其余的则等待同请求返回后,再返回。

Demo

版本

  • v1.1.0

基于

安装

npm install ts-x-request-pool

或者

github下载源码

使用

直接用script引入

<script src="lib/xrequestpool.umd.js"></script>
Vue示例

在main.js引入

import XRequestPool from 'x-request-pool';

获取实例

const insConfig = {
    baseUrl: '', // 会和 requestConfig 的 url 合并
    timeout: 300, // 连接超时时间 秒
    headers: object, // 头文件,具体设置可参考axios
};
const RequestPoolIns = RequestPool.getRequestIns(insConfig);

发送请求

const requestConfig = {
    url: string, // 链接地址
    method: string, //请求方法 GET\POST\DELETE
    headers: object, // 头文件,具体设置可参考axios
    params: object, // get请求时的参数
    data: 'object', // post请求时的参数
};
RequestPool.doRequest(RequestPoolIns, requestConfig).then((result) => {
    this.resultData = `${this.resultData}\n${JSON.stringify(result)}`;
    console.log('result-', result);
}).catch((err) => {
    console.log('err-', err);
});

获取当前连接池里的连接数据

RequestPool.getRequestPools(); // { key: { 具体数据 } }

取消请求

RequestPool.cancelRequest(key?); // 不填写key,则取消所有

Keywords

FAQs

Package last updated on 14 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc