Gathering detailed insights and metrics for express-typed-rpc
Gathering detailed insights and metrics for express-typed-rpc
npm install express-typed-rpc
Typescript
Module System
Node Version
NPM Version
65.3
Supply Chain
96.8
Quality
73.6
Maintenance
100
Vulnerability
100
License
TypeScript (100%)
Verify real, reachable, and deliverable emails with instant MX records, SMTP checks, and disposable email detection.
Total Downloads
3,974
Last Day
2
Last Week
11
Last Month
77
Last Year
2,032
MIT License
3 Stars
27 Commits
2 Watchers
1 Branches
1 Contributors
Updated on Jul 04, 2024
Latest Version
2.0.0
Package Id
express-typed-rpc@2.0.0
Unpacked Size
21.49 kB
Size
7.15 kB
File Count
21
NPM Version
10.2.4
Node Version
21.6.1
Published on
Jan 29, 2024
Cumulative downloads
Total Downloads
Last Day
0%
2
Compared to previous day
Last Week
83.3%
11
Compared to previous week
Last Month
-39.4%
77
Compared to previous month
Last Year
4.6%
2,032
Compared to previous year
WARNING! This repo is still a work in progress. Please contribute if you're interested ❤️
Simple express middleware to easily create a fully-typed JSON API over HTTP on both the server-side and client-side. This project is inspired by tRPC, but much simpler.
Crazy Simple and Easy to Use 😃
infer
keywordMake Your Code More Reliable and Go Faster! 🚀
req
and res
1npm i express-typed-rpc
1import express from 'express'; 2import { Router } from 'express'; 3import { createAPI, InferAPI } from 'express-typed-rpc/dist/server'; 4 5const apiRouter = Router(); 6 7const api = { 8 greet: (name: string): string => `Hello, ${name}!`, 9 multiply: (args: {a: number, b: number}): number => args.a * args.b 10}; 11 12createAPI(apiRouter, api); 13 14// Export type for use on client 15export type API = InferAPI<typeof api>; 16 17const app = express(); 18 19app.use('/api', apiRouter); 20app.listen(process.env.PORT || 3000);
1import {client} from 'express-typed-rpc/dist/client'; 2import type {API} from '@yourorg/server' 3 4const greet = async (name: string): Promise<string> => { 5 return await client<API['greet']>('greet', name, { 6 endpoint: 'https://api.yourdomain.com', 7 options: {} // fetch options (window.RequestInit) 8 }); 9}; 10 11const multiply = async (numbers: {a: number, b: number}): Promise<number> => { 12 return await client<API['multiply']>('multiply', numbers, { 13 endpoint: 'https://api.yourdomain.com', 14 options: {} // fetch options (window.RequestInit) 15 }); 16};
1import {client} from 'express-typed-rpc/dist/client-node'; 2import type {API} from '@yourorg/server' 3 4const greet = async (name: string): Promise<string> => { 5 return await client<API['greet']>('greet', name, { 6 endpoint: 'https://api.yourdomain.com', 7 options: {} // https.RequestOptions 8 }); 9}; 10 11const multiply = async (numbers: {a: number, b: number}): Promise<number> => { 12 return await client<API['multiply']>('multiply', numbers, { 13 endpoint: 'https://api.yourdomain.com', 14 options: {} // https.RequestOptions 15 }); 16};
You must publish your backend as a private repo (Github Packages is recommended). Only the Typescript types are exported/imported and does not affect runtime. You will enjoy the same performance but with IDE autocompletion, validation, and compile-time TypeScript errors.
Please contribute to this project! Issue a PR against main
and request review.
1npm i
1npm test
No vulnerabilities found.
No security vulnerabilities found.