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

apim-tools

v0.5.3

Published

APIM Tools

Downloads

39

Readme

apim-tools

APIM 平台客户端工具,提供 mock 中间件 和 mock 管理 web界面

如何使用?

安装

npm i apim-tools --save-dev

作为 express 中间件使用

function artProcessor(customOptions) {
    return function (mockData, options, context) {
        const tplOptions = {
            tplDir: customOptions.tplDir || options.tplDir || options.baseDir
        };

        return new Promise((resolve, reject) => {
            if (!isPlainObject(mockData)) {
                return resolve({_data: mockData});
            }

            let tpl = mockData._tpl;
            if (tpl) {
                let tplFile = pathUtil.join(tplOptions.tplDir, tpl);
                let tplData = context.normalizeMockData(mockData);
                context.logger.debug('render art template using data', tplData);

                let result = art(tplFile, tplData);
                return resolve({_data: result});
            }
            else {
                context.logger.error('to render tpl file missing');
                return reject('to render tpl file missing');
            }
        });
    };
}

const apimMw = require('apim-tools').express({
    // express server 使用的端口号
    port: 9090,
    // 设置存储的 mock 相关数据存储的根目录
    root: __dirname + '/mock',
    // 项目 schema token 具体到 apim 平台查看
    schemaToken: 'd79e5fa60c5ed6111b6a06a2f4fcbb6b',
    // 是否启动时候立刻自动同步
    startAutoSync: true,
    // 是否开启注入选项,默认会在页面注入 mock 管理的入口
    injector: true,
    // 自定义 mock,只有不存在接口定义 mock 才走该自定义 mock 规则
    // mock 规则定义同 https://github.com/wuhy/autoresponse
    mockRules: [
        {
            match: '/users/:id',
            method: ['get', 'patch']
        }
    ],
    // 自定义 mock 数据处理器或者选项
    processors: {
        // 使用 smarty 处理器,接口平台定义的页面模板类型选择 Smarty
        smarty: {
            baseDir: __dirname + '/mock'
        },
        // 使用 etpl 处理器,接口平台定义的页面模板类型选择 ETPL
        etpl: {
            tplDir: __dirname + '/templates',
            tplExtName: 'etpl',
            encoding: 'utf-8',
            engine: {
                commandOpen: '{{',
                commandClose: '}}',
                variableOpen: '{%',
                variableClose: '%}'
            },
            filters: { // 默认提供 json_encode 
                myFilter: function (source) {
                    return source;
                }
            }
        },
        // 自定义 art-template 处理器,接口平台定义的页面模板类型选择其它,
        // 默认的处理器名为模板的文件扩展名
        art: artProcessor({
            tplDir: __dirname + '/templates'
        })
    }
});
app.use(apimMw);

API

  • testAPI
const apim = require('apim-tools')({
    root: __dirname + '/mock'
});
let promise = apim.testAPI({
    path: '/api/getUserInfo?uid=22', // 请求路径
    method: 'get', // 请求方法
    body: {}, // body 数据,可选
    envId: 11, // 可选,默认使用配置的环境
});
let expressMw = apim.express;
// ...

访问 mock 管理界面

http://devServer:devPort/apimclient