@vishalsharma7nov/react-native-proto
v0.2.4
Published
Dynamic React Native protobuf client with generate CLI, HTTP/Connect transports, interceptors, and typed errors
Maintainers
Readme
@vishalsharma7nov/react-native-proto
A React Native / TypeScript client for protobuf APIs.
Point it at your .proto files (local folder, GitHub, or Buf), generate typed client methods, and call your server:
const user = await api.userService.getUser({ id: '1' });- GitHub: https://github.com/vishalsharma7nov/react-native-proto
- npm: https://www.npmjs.com/package/@vishalsharma7nov/react-native-proto
- License: MIT
Install
npm install @vishalsharma7nov/react-native-protoOr from GitHub Packages (add to .npmrc):
@vishalsharma7nov:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=YOUR_GITHUB_TOKENQuick start
1. Config (in your app, not in node_modules)
import type { ProtoClientConfig } from '@vishalsharma7nov/react-native-proto';
const config: ProtoClientConfig = {
baseUrl: 'https://api.example.com',
getHeaders: async () => ({
Authorization: `Bearer ${await getToken()}`,
}),
};
export default config;2. Call your API
import { createClient, isProtoClientError } from '@vishalsharma7nov/react-native-proto';
import config from './react-native-proto.config';
const api = createClient(config);
try {
const user = await api.userService.getUser({ id: '1' });
console.log(user);
} catch (e) {
if (isProtoClientError(e)) {
console.error(e.code, e.message);
}
}What you get
- Dynamic client from proto
service/rpcdefinitions - Typed
create-api.ts+message-types.tsfrom generate - Transports: HTTP + protobuf, Connect (unary + streaming), native HTTP/protobuf unary
- Interceptors (auth refresh, logging), offline queue, path presets, version headers
- Optional Zod validation wrappers
- CLI:
generate/sync/watch(local, GitHub, or Buf) - Optional React Query + Metro helpers
- Node mock server (
@vishalsharma7nov/react-native-proto/mock-server) - Expo config plugin
Generate from your own protos
# Local folder
npx react-native-proto generate --from local --path ./protos --out ./src/generated
# Watch local protos
npx react-native-proto watch --from local --path ./protos --out ./src/generated
# GitHub (pin a tag or commit)
npx react-native-proto generate --from github --repo https://github.com/you/protos.git --ref v1.0.0 --out ./src/generated
# Buf module
npx react-native-proto generate --from buf --module buf.build/acme/petapis --ref 1.0.0 --out ./src/generated
# App-local generate (import runtime from this package)
npx react-native-proto generate --from local --path ./protos --out ./src/generated \
--import-from @vishalsharma7nov/react-native-protoYour .proto files must include service and rpc blocks.
Docs
Full documentation lives in the repo:
| Doc | What it explains | |-----|------------------| | Getting started | Step-by-step setup | | Architecture | Layers and request flow | | Config | Config fields | | Generate | Local / GitHub / Buf generate | | Errors | Error codes | | Troubleshooting | Common problems | | Changelog | Release notes |
Example apps
- Expo demo:
example/ - Vite web demo:
examples/web/
