New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

@yuankui/rpc-express

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@yuankui/rpc-express

Express integration for @yuankui/rpc

latest
Source
npmnpm
Version
0.2.1
Version published
Maintainers
1
Created
Source

@yuankui/rpc-express

Express integration for @yuankui/rpc - A type-safe RPC framework.

Installation

npm install @yuankui/rpc-express
# or
yarn add @yuankui/rpc-express
# or
bun add @yuankui/rpc-express

Usage

Basic Setup

import express from 'express';
import { createRPCRouter } from '@yuankui/rpc-express';

const app = express();
app.use(express.json());

// Define your RPC endpoints
const endpoints = {
  async getUser(id: number) {
    // Your logic here
    return { id, name: 'John Doe' };
  },
  async createUser(name: string, email: string) {
    // Your logic here
    return { id: 1, name, email };
  },
};

// Create RPC router
const rpcRouter = createRPCRouter({
  endpoints,
  path: '/api/rpc', // Optional, defaults to '/rpc'
});

app.use(rpcRouter);

app.listen(3000, () => {
  console.log('Server running on port 3000');
});

Using with Express Router

import { Router } from 'express';
import { createRPCMiddleware } from '@yuankui/rpc-express';

const apiRouter = Router();

const rpcMiddleware = createRPCMiddleware({
  endpoints: {
    async ping() {
      return 'pong';
    },
  },
});

apiRouter.use('/rpc', rpcMiddleware);

Custom Serialization

import { createRPCRouter } from '@yuankui/rpc-express';

const rpcRouter = createRPCRouter({
  endpoints: {
    async getData() {
      return new Date(); // Will be properly serialized
    },
  },
  serializer: {
    serialize: (data) => JSON.stringify(data),
    deserialize: (data) => JSON.parse(data),
  },
});

API

createRPCRouter(config)

Creates an Express router with RPC endpoint handling.

Parameters

  • config.endpoints - Object containing your RPC endpoint functions
  • config.path - (Optional) RPC endpoint path, defaults to /rpc
  • config.serializer - (Optional) Custom serializer, defaults to superjson

Returns

Express Router instance

createRPCMiddleware(config)

Alias for createRPCRouter for better semantic clarity when using as middleware.

ExpressRPCHandler

Class for more advanced usage scenarios where you need direct control over the handler.

Client Usage

Use with the standard RPC client:

import { RPCClient } from '@yuankui/rpc-express';

type ServerEndpoints = {
  getUser: (id: number) => Promise<{ id: number; name: string }>;
  createUser: (name: string, email: string) => Promise<{ id: number; name: string; email: string }>;
};

const client = new RPCClient<ServerEndpoints>({
  url: 'http://localhost:3000/api/rpc',
});

// Type-safe calls
const user = await client.call('getUser', 123);
const newUser = await client.call('createUser', 'Jane', 'jane@example.com');

License

MIT

Keywords

rpc

FAQs

Package last updated on 28 Jun 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts