Registry / devops / rpc-request

rpc-request

JSON →
library10.0.0jsnpmunverified

A lightweight wrapper around the Fetch API provided as a class, supporting JSON/text transforms, base URLs, automatic rejection on non-OK status, and typed HTTP methods (get, post, put, patch, delete). Version 10.0.0 requires Node >=24.16.0 and ships TypeScript types. It differentiates itself by offering a simple, class-based interface with optional transform and reject options, making it easy to extend for custom API clients.

npm install rpc-request
INSTALL
IMPORT
SIG · RPC-REQUEST
R
rpc-request
devopsjavascriptv10.0.0
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.

Fetch
import { Fetch } from 'rpc-request'
const Fetch = require('rpc-request')
ESM only; CommonJS require does not work due to module type.
UnsuccessfulFetch
import { UnsuccessfulFetch } from 'rpc-request'
import UnsuccessfulFetch from 'rpc-request'
Named export, not default.
FetchOptions
import type { FetchOptions } from 'rpc-request'
import { FetchOptions } from 'rpc-request'
FetchOptions is a type; use import type for type-only imports.

Shows how to create a Fetch client with base URL, JSON transform, and rejection on non-OK status, then make a typed GET request.

import { Fetch } from 'rpc-request'; interface IpInfo { client_ip: string; timezone: string; } const client = new Fetch({ base_url: new URL('http://worldtimeapi.org/api/'), transform: 'json', reject: true, }); const info = await client.get<IpInfo>('ip'); console.log(info);
Debug
Known issues
breakingNode.js version requirement: >=24.16.0
fix
Upgrade Node.js to version 24.16.0 or later. Alternatively, use an older version of rpc-request (9.x or below) which supports lower Node versions.
affects: >=10.0.0
deprecatedThe 'transform' option is now required to get automatic response parsing. In older versions, transform was optional and defaulted to no transformation.
fix
Explicitly set transform: 'json' or 'text' in Fetch constructor options.
affects: >=10.0.0
gotchaWhen transform is not set, the raw Response object is returned regardless of reject option. reject only works when transform is provided.
fix
Always set a transform if you want automatic error handling or response parsing.
affects: >=1.0.0
gotchaThe base_url option expects a URL object, not a string. Passing a string will cause a runtime error.
fix
Use `new URL('http://example.com/')` instead of a plain string.
affects: >=10.0.0
breakingNamed export 'Fetch' instead of default export. CommonJS require('rpc-request') will not work.
fix
Use ES module import syntax: `import { Fetch } from 'rpc-request'`
affects: >=10.0.0
Errors
Common errors & fixes
TypeError: Class constructor Fetch cannot be invoked without 'new'
Using `Fetch()` without the `new` keyword.
fix
Use `new Fetch(options)` instead of `Fetch(options)`.
Error: base_url must be a URL object
Passing a string for `base_url` option instead of a `URL` object.
fix
Use `new URL('http://example.com')` for the `base_url` option.
Error: UnsuccessfulFetch: <status> <statusText>
HTTP request returned a non-OK status (e.g., 404) and `reject: true` was set with a transform.
fix
Handle the error with try/catch, or set `reject: false` to return the response without throwing.
TypeError: Failed to parse URL from ...
Incorrect base_url or path combination resulting in an invalid URL.
fix
Ensure base_url ends with a trailing slash if paths are relative, or use absolute URLs in path.
Upgrade
Version history
10.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
Amazon
1
Resources
rpc-request — npm install rpc-request · libregistry