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

rpc-sync

v1.0.53

Published

Generates RPC code for a compatible remote API

Downloads

227

Readme

rpc-sync

Server and client, type defined, Remote Procedure Call.

Client Installation

First install rpc-sync globally

npm install -g rpc-sync

Create rpc.json

First create a rpc.json file in the root of your project:

{
    "url": "http://api.example.com/api",
    "secret: null
    "target": "ReactTypeScript",
    "output": "src/rcpClient.ts",
    "namespace": "rcpClient",
}

url

Replace the url parameter value with the URL of your remote API server.

secret

If your API server requires a secret in order to obtain the schema/documentation supply the secret in this parameter

target

Targets include:

  • ReactTypeScript
  • TypeScript
  • Dart
  • VisualBasic

output

The output source file generated by rpc-sync.

namespace

The namespace/class for the generated source files.

Sync project RPC references

Run the following command from your project root. You can re-run this command to update any API reference changes.

rpc-sync

or

rpc-sync rpc.json

Server Installation

Create a Node Typescript with Express project, then install the following package:

npm install rpc-sync

Now using the example below setup an express API using rpc-sync:

import express from "express";
import path from "path";
import rpcSync from "rpc-sync";
import HelloWorldAPI from "src/api/helloWorldAPI"

export interface IContext {
    req: express.Request;
    res: express.Response;
}

const port = 3000;
const app = express();

app.listen(port, () => {
    console.log("Listening on port:", port);

rpcSync.server.buildAPI({
        srcPath: path.join(process.cwd(), "/src"),
        apiPath: path.join(process.cwd(), "/src/api"),
        entityPath: path.join(process.cwd(), "/src/entity"),
        schemaOutputPath: path.join(process.cwd(), "schema.json"),
        enableDocs: true,
        enableClientSchema: true,
        minClientVersion: "0.1",
        debug: true,
    }).then((build)=>{
            rpcSync.server.exposeExpressAPI(build, app, (request) => {
                // This occurs on every web request.
                // Build a context object.. this can be anything. It will be sent to the API method as the first parameter.
                const context: IContext = {
                    req: request.req,
                    res: request.res
                };

                //Here is a good place to setup the database connection, apply authentication etc.
                //Expose the APIs to the request
                request.expose(context, {
                    "helloWorld": HelloWorldAPI
                });
            }).catch((e) => {
                console.error(e);
            });
    }).catch((e)=>{
            console.error(e)
    });
});
// src/api/helloWorldAPI.ts
interface IHelloWorldParameters {
    myTestValue: string;
}
interface IHelloWorldResult {
    myResult: string;
}
export class HelloWorldAPI {
    static async helloWorld(context: IContext, parameters: IHelloWorldParameters): Promise<IHelloWorldResult> {
        return new Promise<IHelloWorldResult>((accept, reject) => {
            accept({
                myResult: `Hello ${parameters.myTestValue}!`
            });
        });
    }
}
// src/entity

You can leave this directory empty.