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

@nxapi/kxapi

v0.1.1

Published

@nxapi/kxapi

Readme

kxapi

kxapi 是一个 api 框架,底层基于 koa。它重新定义了一套 api 的写法。市面上主流的 api 框架有 hapi、egg,在接口定义上都有些缺点,没有牛 x 框架 springboot 使用的流畅。kxapi 在接口定义方面很像 springboot,所以我们有理由相信这样的方式是正确的。

使用

安装

npm i @nxapi/kxapi -S

配置

在根目录配置 .kxapirc.js 文件,内容如下:

module.exports = {
  rootDir: 'src', //根目录
  outputDir: '__tmp__', //输出目录
  ctrlDir: 'controllers', //需要转DSL目录
  serviceDir: 'services', //service层目录
  plugins: ['@nxapi/nxapi-dsl-koa', '@nxapi/nxapi-dsl-joi', '@nxapi/nxapi-dsl-swagger-json'], //根据DSL生成对应代码
};

执行

kxapi build|watch

如何定义接口

直接上代码,很常规的函数定义,对于装饰器不多解释,查查手册

// controllers/req/test-req.ts
export class TestReq {
  @d.string.required()
  @d.string.max(10)
  @d.string.allow('v1', 'v2')
  @d.string.error(() => '错误描述')
  test: string;
}
// controllers/base-response.ts
export default class BaseResponse<T> {
  code: string;
  msg: string;
  data: T;
}
// controllers/dto/test-dto.ts
export default class TestDto {
  @d.string.required()
  test: string;
}
// controllers/hello-controller.ts
import { d } from '@nxapi/nxapi';
import { TestReq } from './req/test-req';
import TestDto from './req/test-dto';
import { BaseController } from '@nxapi/kxapi';

//类必须继承 BaseController
@d.controller.path('/v1')
export default class HelloController extends BaseController {
  @d.function.get('/hello')
  @d.function.description('接口描述')
  public hello(req: TestReq): BaseResponse<TestDto> {
    return 'hello';
  }
}

这样一个常规的接口就完成了。更多请查看

service 定义

import { BaseService } from '@nxapi/kxapi';

//类必须继承 BaseService
export default class TestService extends BaseService {
  public test() {}
}

内置变量

  • controller 和 service 中都内置了 ctx、service