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

@wujingze-self/arkwebapiplugin

v1.0.12

Published

ark web api controller

Readme

适用于鸿蒙的路由方法插件

在ArkWeb项目中,前端调用鸿蒙原生的方法需要使用javaScriptProxy,需要创建我们自己的代理对象,该代理对象中会包含大量的自定义方法,还需要维护大量的方法名字符串,比较难以维护。

arkwebapiplugin插件就是将一个个处理方法与path进行映射,类似于spring bootcontroller

引入插件

  1. 首先需要新建两个装饰器(注解)
/**
 * 装饰器controller,作用于类
 * @param parma
 * @returns
 */
export function WebApiController(parma: WebApiControllerParams) {
  return Object;
}

export interface WebApiControllerParams {
  basePath: string;
}

/**
 * 装饰器mapper,作用于方法
 * @param params
 * @returns
 */
export function WebApiMethod(params: WebApiMethodParams) {
  return (target: ESObject, propertyKey: string, descriptor: PropertyDescriptor) => {
  };
}

export interface WebApiMethodParams {
  path: string;
  requestType?: 'GET' | 'POST' | 'PUT' | 'DELETE';
}
  1. 引入插件

hvigor/hvigor-config.json5中引入插件依赖

"dependencies": {
    "@wujingze-self/arkwebapiplugin": "1.0.12"
}
  1. 使用插件

在需要使用该插件的模块的hvigorfile.ts中使用插件

import { hapTasks } from '@ohos/hvigor-ohos-plugin';
import { modulePlugin } from '@hadss/hmrouter-plugin';
import { scanWebApiPlugin } from '@wujingze-self/arkwebapiplugin';

export default {
  system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
  plugins: [modulePlugin(), scanWebApiPlugin('src/main/ets/pages/day34/webapi')] // 初始化传入需要扫描的包
}

如何使用

  1. 在扫描的包下创建Controller

    import { WebApiController, WebApiMethod } from "library_arkweb_api";
       
    @WebApiController({ basePath: '/user' })
    export default class UserController {
      @WebApiMethod({ path: '/add', requestType: 'PUT' })
      addUser() {
       
      }
       
      @WebApiMethod({ path: '/find', requestType: 'GET' })
      findUser() {
       
      }
       
      @WebApiMethod({ path: '/delete', requestType: 'DELETE' })
      deleteUser() {
       
      }
       
      @WebApiMethod({ path: '/login', requestType: 'POST' })
      login() {
       
      }
    }
  2. 重新build一下模块Generate Build Profile

    此时会在当前模块下生成src/main/ets/webapi/generated/WebApiControllerManager.ets

       
    import BuildController from "../../pages/day34/webapi/controller/BuildController"
    import ShopController from "../../pages/day34/webapi/ShopController"
    import UserController from "../../pages/day34/webapi/UserController"
       
    export default class WebApiControllerManager {
       
        static readonly putMethod = new Map<string,(params?:object)=>object|void>()
        static readonly getMethod = new Map<string,(params?:object)=>object|void>()
        static readonly postMethod = new Map<string,(params?:object)=>object|void>()
        static readonly deleteMethod = new Map<string,(params?:object)=>object|void>()
       
        static {
            const BuildControllerInstance = new BuildController()
            const ShopControllerInstance = new ShopController()
            const UserControllerInstance = new UserController()
               
            WebApiControllerManager.putMethod.set(
                "/build/add",
                BuildControllerInstance.addBuild.bind(BuildControllerInstance)
            )
       
            WebApiControllerManager.putMethod.set(
                "/shop/add",
                ShopControllerInstance.addShop.bind(ShopControllerInstance)
            )
       
            WebApiControllerManager.putMethod.set(
                "/user/add",
                UserControllerInstance.addUser.bind(UserControllerInstance)
            )
       
            WebApiControllerManager.getMethod.set(
                "/user/find",
                UserControllerInstance.findUser.bind(UserControllerInstance)
            )
       
            WebApiControllerManager.deleteMethod.set(
                "/user/delete",
                UserControllerInstance.deleteUser.bind(UserControllerInstance)
            )
       
            WebApiControllerManager.postMethod.set(
                "/user/login",
                UserControllerInstance.login.bind(UserControllerInstance)
            )
       
        }
       
    }
  3. 这样就可以根据请求类型和请求path得到对应的函数进行调用了,javaScriptProxy的代理对象只需要添加一个方法,进行路由的处理即可