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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@steedos/service-sidecar

v2.6.38

Published

Downloads

3,693

Readme

提供接口

总览


| 方法 | 地址 | 用途 | | :--- | :--- | :--- | | GET | /service/api/$sidecar/registry/nodes | 获取nodes | | GET | /service/api/$sidecar/registry/services | 获取services | | GET | /service/api/$sidecar/registry/actions | 获取actions | | GET | /service/api/$sidecar/registry/events | 获取events | | POST | /service/api/$sidecar/registry/services | 注册service | | DELETE | /service/api/$sidecar/registry/services/:serviceName | 注销service | | POST | /service/api/$sidecar/call/:action | 调用action | | POST | /service/api/$sidecar/emit/:event | 触发event | | POST | /service/api/$sidecar/broadcast/:event | 广播event |

说明


接口认证

  • 添加请求头 Authorization: Bearer apikey,{apiKey}, {apiKey}值从华炎魔方平台-高级设置-API Key菜单获取

注册service

请求正文格式为 MoleculerJS Service,需要注意的是sidecar会使用POST方式调用action或event接口,示例:

POST /service/api/$sidecar/registry/services

请求体

{
    name: "posts",
    version: 1,

    settings: {
        // It means, your HTTP server running on port 5000 and sidecar can reach it on `localhost`
        // The URLs in action/event handlers contains relative URL.
        baseUrl: "http://localhost:5000"
    },

    actions: {
        list: {
            params: {
                limit: "number",
                offset: "number"
            },
            // Shorthand handler URL what will be called by sidecar
            handler: "/actions/posts/list"
        }
    },

    events: {
        "user.created": {
            // Shorthand handler URL what will be called by sidecar
            handler: "/events/user.created"
        }
    }
}

调用action

调用service的action,示例:

POST /service/api/$sidecar/call/comments.create

请求体

{
    // Context params
    params: {
        title: "Lorem ipsum",
        content: "Lorem ipsum dolor sit amet..."
    },
    // Context meta
    meta: {
        user: {
            id: 12345
        }
    },
    // Calling options
    options: {
        timeout: 3000
    }
}

响应体

{
    // Response data
    response: {
        id: 1,
        title: "Lorem ipsum",
        content: "Lorem ipsum dolor sit amet..."
    },
    // Optional: Context meta if you changed the content.
    meta: {
        user: {
            id: 12345
        }
    }
}

报错响应

{
    error: {
        name: "MoleculerClientError",
        code: 422,
        type: "VALIDATION_ERROR",
        message: "Title is required",
        data: {
            action: "comments.create",
            params: {
                title: null
            }
        }
    }
}

触发event

触发某个服务的事件,示例:

POST /service/api/$sidecar/emit/post.created

广播则使用如下URL,示例:

POST /service/api/$sidecar/broadcast/post.created

Request body

{
    // Context params
    params: {
        id: 1,
        title: "First post",
        content: "Post content",
        author: 12345
    },
    // Context meta
    meta: {
        user: {
            id: 12345
        }
    },
    // Emit options
    options: {
        groups: "users"
    }
}

接受action请求

如果注册的service定义了action,其他服务调用action时sidecar会使用POST方法调用action中定义的handler地址,请求正文如下:

请求体

{
    // Action name
    action: "posts.list",

    // Caller NodeID
    nodeID: "node-123",

    // Context params
    params: {
        limit: 10,
        offset: 50
    },

    // Context meta
    meta: {
        user: {
            id: 12345
        }
    },

    // Calling options
    options: {
        timeout: 3000
    }
}

action中定义的handler地址,返回值应是如下格式:

响应体

{
    // Response data
    response: [
        { id: 1, title: "First post" },
        { id: 2, title: "Second post" },
        { id: 3, title: "Third post" }
    ],
    // Optional: Context meta if you changed the content.
    meta: {
        user: {
            id: 12345
        }
    }
}

如果执行过程中报错,sidecar会返回如下格式响应正文:

报错响应

{
    // Error data
    error: {
        name: "MoleculerClientError",
        code: 400,
        type: "INVALID_INPUT",
        message: "Some user input is not valid",
        data: {
            // Any useful data
            action: "posts.list",
            params: {
                limit: "asd"
            }
        }
    }
}

接受event请求

如果注册的service定义了event,其他服务调用event时sidecar会使用POST方法调用event中定义的handler地址,请求正文如下:

请求体

{
    // Event name
    event: "user.created",

    // Type of event (emit, broadcast)
    eventType: "emit",

    eventGroups: "posts",

    // Caller NodeID
    nodeID: "node-123",

    // Context params
    params: {
        limit: 10,
        offset: 50
    },

    // Context meta
    meta: {
        user: {
            id: 12345
        }
    }
}

响应和报错与action一样。