Registry / api-client / grpc-xhr

grpc-xhr

JSON →
library1.0.13jsnpmunverified

A lightweight JavaScript library for making AJAX requests to gRPC-web or gRPC Gateway endpoints from the browser. Current stable version is 1.0.13 with low release cadence (last release 2023). Provides a simple Promise-based interface for streaming and unary gRPC calls over XHR, without requiring gRPC-web or a service worker. Smaller bundle size compared to gRPC-web client, but limited to browser environments and lacks advanced features like client-side interceptors or metadata manipulation.

npm install grpc-xhr
INSTALL
IMPORT
SIG · GRPC-XHR
G
grpc-xhr
api-clientjavascriptv1.0.13
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import GrpcXhr from 'grpc-xhr'
const GrpcXhr = require('grpc-xhr')
Package supports only ESM imports. CommonJS require will result in errors.
GrpcXhrClient
import { GrpcXhrClient } from 'grpc-xhr'
import GrpcXhrClient from 'grpc-xhr'
Named export for the client class. Default export is the factory function, not the class.
grpcXhrFactory
import { grpcXhrFactory } from 'grpc-xhr'
const { grpcXhrFactory } = require('grpc-xhr')
Utility function to create a configured client. ESM only; no CommonJS support.

Shows how to create a gRPC XHR client and perform unary and streaming requests.

import GrpcXhr, { GrpcXhrClient } from 'grpc-xhr'; const client = new GrpcXhrClient({ baseURL: 'https://api.example.com', headers: { 'X-API-Key': process.env.API_KEY ?? '' } }); // Unary call const request = { name: 'Alice' }; void client.unary('/myapp.MyService/GetUser', request) .then(response => console.log(response)) .catch(err => console.error(err)); // Server streaming const stream = client.stream('/myapp.MyService/ListUsers', {}); for await (const chunk of stream) { console.log(chunk); }
Debug
Known issues
breakingPackage is ESM-only since v1.0.0. Do not use require().
fix
Use import syntax and ensure your environment supports ES modules.
affects: >=1.0.0
gotchaThe client does not support gRPC-web trailers. Use unary calls only for non-streaming endpoints.
fix
For streaming, verify your gRPC-Gateway configuration returns response immediately.
affects: >=0.1.0
deprecatedThe package recommends google-protobuf, but @grpc/grpc-js is not supported for proto marshalling.
fix
Use google-protobuf for message encoding/decoding. Do not mix with @grpc/grpc-js.
affects: >=0.9.0
breakingIn v1.0.0, the constructor signature changed; previous options format is invalid.
fix
Initialize client with { baseURL, headers } directly; no nested 'options' key.
affects: >=1.0.0
Errors
Common errors & fixes
ReferenceError: require is not defined
Using CommonJS require instead of ESM import.
fix
Replace const GrpcXhr = require('grpc-xhr') with import GrpcXhr from 'grpc-xhr'.
TypeError: grpcXhrFactory is not a function
Mistaking default export for named export.
fix
Use import { grpcXhrFactory } from 'grpc-xhr'.
Uncaught (in promise) TypeError: Failed to execute 'open' on 'XMLHttpRequest': Invalid URL
Missing baseURL or incorrect URL format.
fix
Ensure baseURL is a valid absolute URL (e.g., https://example.com).
Upgrade
Version history
1.0.13latest on npm
Audit
Dependencies
google-protobufrequiredRequired for Protobuf message serialization/deserialization.
whatwg-fetchoptionalPolyfill for fetch API needed in older browsers (optional if fetch is natively supported).
Agent activity
39 hits · last 30 days
node
34
OpenAI (training)
1
Resources
grpc-xhr — npm install grpc-xhr · libregistry