npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@polyv/request-core

v2.8.1

Published

保利威前端项目请求库,用于前端项目的请求封装。

Downloads

601

Readme

保利威业务请求库

保利威前端项目请求库,用于前端项目的请求封装。

安装

npm install @polyv/request-core --save

使用

import { PolyvRequest } from '@polyv/request-core';

// 实例化请求器
const requester = new PolyvRequest({
  baseUrl: '//api.polyv.net',
});

(async () => {
  // 执行请求
  const data = await requester.get('/getDetail', {
    channelId: 'xxxx',
  });

  console.log(data);
})();

使用 Typescript:

// 自定义请求选项
interface CustomRequestOptions {
  test?: boolean;
}

// 实例化请求器
const requester = new PolyvRequest<CustomRequestOptions>({
  baseUrl: '//api.polyv.net',
});

interface ChannelDetail {
  channelName: string;
}

(async () => {
  // 执行请求
  const data = await requester.get<ChannelDetail>(
    '/getDetail',
    {
      channelId: 'xxxx',
    },
    {
      test: true,
    },
  );

  console.log(data.channelName);
})();

实例化参数

| 参数名 | 用途 | 类型 | 默认值 | | --------------- | ---------------------- | -------------------- | -------- | | baseUrl | 接口请求地址前缀 | string \| function | '' | | requestPlugins | 请求插件 | RequestPlugin[] | [] | | timeout | 超时时间,毫秒 | number | 10000 | | requestType | 请求方式 | RequestType | 'form' | | responseType | 响应格式 | ResponseType | 'json' | | withCredentials | 跨域请求时是否提供凭据 | boolean | false |

发送请求

发送 GET 请求

// 后端接口返回的 Response
interface ChannelDetailResponse {
  code: number;
  data: {
    /** 频道名称 */
    channelName: string;
  };
}

// 接口入参参数
interface ChannelDetailRequestParams {
  /** 频道号 */
  channelId: string;
}

const res = await requester.get<ChannelDetailResponse, ChannelDetailRequestParams>('/getDetail', {
  channelId: 'xxxx',
});

console.log('code', res.code);
console.log('channelName', res.data.channelName);

发送 POST 请求

interface Response {
  code: number;
  message: string;
}

interface RequestData {
  userId: number;
  name: string;
}

const res = await requester.post<Response, RequestData>(
  '/save-name',
  {
    userId: 123,
    name: '小明',
  },
  {
    // 如果需要额外入参地址参数
    params: {
      channelId: 'xxx',
    },
  },
);

if (res.code === 200) {
  console.log('提交成功');
}

请求选项

请求器实例的 get、post 方法的第三个入参为请求选项,详细类型查看 RequestOptions 类型。

请求插件

@polyv/request-plugin-xxx 为请求库的插件,使用方式如下:

import { PolyvRequest } from '@polyv/request-core';
import { GlobalParamsRequestPlugin } from '@polyv/request-plugin-global-params';
import { StatusCodeRequestPlugin } from '@polyv/request-plugin-status-code';

const requester = new PolyvRequest({
  requestPlugins: [
    // 创建插件并传入 requestPlugins
    new GlobalParamsRequestPlugin({
      globalParams: {
        viewerId: 'xxx',
        channelId: 'xxx',
      },
    }),
    new StatusCodeRequestPlugin(),
  ],
});

插件概览

| 插件名 | 用途 | | -------------------------------------------------------------------------------------------------------------------------------- | ---------------------- | | @polyv/request-plugin-global-params | 全局 params 入参插件 | | @polyv/request-plugin-authorize-token | 请求令牌插件 | | @polyv/request-plugin-authorize-app-sign | 请求签名插件 | | @polyv/request-plugin-status-code | 状态码处理插件 | | @polyv/request-plugin-aes-decrypt | AES 解密响应内容 | | @polyv/request-plugin-aes | AES 业务请求加密和解密 | | @polyv/request-plugin-sm2 | SM2 业务请求加密和解密 |