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

@gopowerteam/http-request-cli

v0.4.22

Published

---

Downloads

120

Readme

@gopowerteam/http-request-cli


npm version install size

基于@gopowerteam/http-request的接口请求配置代码生成器

目录


安装


// yarn use
# yarn add @gopowerteam/http-request-cli

// npm use
# npm install @gopowerteam/http-request-cli --save

示例


在根目录下创建http-request-cli.config.js配置文件

module.exports = {
  "gateway": "http://gateway.xxx.com",
  "swagger:": "v2/api-docs",
  "controllerDir": {
    "alias": "../controller",   // 控制器目录名别
    "path": "./src/controller"  // 控制器目录路径
  },
  "serviceDir": {
    "alias": "@/http/services", // 服务目录名别
    "path": "./src/services" // 服务目录名别
  }
}
# npx http-request-cli -g 
// OR
# npx http-request-cli --generate

执行后会在对应目录下生成配置文件,之后按照@gopowerteam/http-request文档中配置使用即可.

配置

| 名称 | 描述 | 必填 | | :-----------------: | :------------------------: | :---: | | gateway | 服务器/网管地址 | 是 | | swagger | SwaggerJSON Api 地址 | 是 | | controllerDir.alias | 接口controller目录别名配置 | 是 | | controllerDir.path | 接口controller目录路径配置 | 是 | | serviceDir.alias | 接口service目录别名配置 | 是 | | serviceDir.path | 接口service目录路径配置 | 是 | | services | 多服务配置 | 否 | | controllerResolver | 自定义Contrller解析 | 否 |

多服务配置需要添加服务数组services

services:{
    "service-1":"service-1",
    "service-2":"service-2",
    "service-3":"service-3"
}

// key为生成service目录名称
// value为请求调用的service名称

多网管按数组配置即可

module.exports = [
  {
    ...
  },
  {
    ...
  }
];

自定义ControllerResolver

默认情况下会通过path来分析对应的Controller名称来生成文件名和类名,在一些情况下如果不满足需要可以自定义ControllerResolver来解决

  controllerResolver(path, currentTag, tags) {
    const tag = tags.find((x) => x.name === currentTag[0]);
    return tag.description.replace(/\s/g, "").replace(/Controller$/, "");
  }

需要服务重命名也可以使用controllerResolver

controllerResolver: () => "New Name"

自定义ActionResolver

默认情况下会通过获取operationId来获取action名称,在一些情况下如果不满足需要可以自定义ActionResolver来解决

  actionResolver(operationId, method, path) {
    return operationId.replace(/\_.*$/g, "");
  }

Vite插件支持

支持作为vite插件使用,这样可以不需要导入对应的service

vite.config.ts

import { requestPlugin } from '@gopowerteam/http-request-cli'


...
plugins: [
  requestPlugin({
        root: path.resolve(__dirname, 'src'),
        alias: '~',
        serviceDir: 'http/services',
        serviceDeclaration: 'typings/request.d.ts'
  })
]

配置插件后使用时如下即可:

import { useRequest } from 'virtual:http-request'

const posterService = useRequest(
  services => services.PosterService
)

posterService.create(new RequestParams(...))