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 🙏

© 2024 – Pkg Stats / Ryan Hefner

api-init

v1.1.8

Published

Web engineering project API initialization

Downloads

40

Readme

使用

使用 npx 执行

  1. 安装 api-init
npm install api-init --save-dev
  1. 项目接口 API 初始化命令
  • 初始化,默认路径(default: src/api)
npx api-init install
  • 自定义路径,嵌套路径用/连接(如:src/api)
npx api-init install api
  1. 生成接口文档(注:文档路径需要和接口 api 初始化路径相同)
  • api 初始化使用默认路径,则文档命令:
npx api-init docs
  • api 初始化使用自动义(如:api),则文档命令:
npx api-init docs api

使用 npm 执行

  1. 安装 api-init
npm install api-init --save-dev
  1. package.json 添加 npm scripts 命令
// package.json
{
  "scripts": {
    "api-init": "api-init",
  }
}
  1. 项目接口 API 初始化命令
  • 初始化,默认路径(default: src/api)
npm run api-init install
  • 自定义路径,嵌套路径用/连接(如:src/api)
npm run api-init install api

4.生成接口文档(注:文档路径需要和接口 api 初始化路径相同)

  • api 初始化使用默认路径,则文档命令:
npm run api-init docs
  • api 初始化使用自动义(如:api),则文档命令:
npm run api-init docs api

接口 API 默认结构

├── src
    ├── api
        ├── docs
            └── index.js        #生成接口文档明显
        ├── modules
            ├── example.js      #接口模块配置
            └── ...
        ├── request
            ├── config.js       #公共请求方法配置
            └── index.js        #封装公共请求方法
        ├── docs.json           #接口方法明显
        └── index.js            #自动生成接口方法
    ├── ...

添加接口配置

在 api/modules 目录下添加对应的模块,按照规定添加对应配置项目,就可以生成对应的接口方法,如:

// 1、modules添加example.js模块
// 2、添加接口对应配置项
export default [
  {
    name: "query", // 接口方法名取接口url最后一个单词
    method: "get", // 接口请求方法
    url: "example/query", // 接口url
    params: {}, // 接口默认传参
    docs: "接口说明", // 接口说明注释
  },
];

使用

// api文件夹配置别名api
import api from 'api' // 或 import api from '@/api'

// 使用
api.example.query({ // 参数 })

相关地址

api-init 文档地址: https://hugolgw.github.io/api-main

api-init npm 地址: https://www.npmjs.com/package/api-init

api-init 源码地址: https://github.com/hugolgw/api-main

原创不易,欢迎 star

License

MIT