Registry / devops / node-rest-api-client

node-rest-api-client

JSON →
library4.0.0jsnpmunverified

A simple-to-use HTTP REST API client for Node.js supporting GET, POST, PUT, DELETE, PATCH, and custom methods. Version 4.0.0 provides transparent HTTP/HTTPS connections, basic authentication, proxy support, dynamic path and query parameters, custom request serializers (JSON, XML, url-encoded), custom response parsers (JSON, XML), compressed response handling (gzip, deflate), and follow-redirects. It allows registering remote API operations as client methods. Latest stable release has irregular release cadence; key differentiator is its simple callback-based API without promises, but it lacks TypeScript support.

npm install node-rest-api-client
INSTALL
IMPORT
SIG · NODE-REST-API-CLIE
N
node-rest-api-client
devopsjavascriptv4.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.

Client
const { Client } = require('node-rest-client');
const Client = require('node-rest-client');
CommonJS export is { Client } not default export. Requires require destructuring.
Client (ESM)
import { Client } from 'node-rest-client';
import Client from 'node-rest-client';
Package is CJS only; ESM import works via interop but named import is correct.
Methods from client instance
client.registerMethod('myMethod', url, 'GET'); client.methods.myMethod(callback);
Register methods before use; methods property contains all registered methods.

Shows direct GET, registered method with path substitution, and POST with JSON data and headers.

const { Client } = require('node-rest-client'); const client = new Client(); // Direct GET client.get('https://jsonplaceholder.typicode.com/posts/1', function(data, response) { console.log('Data:', data); console.log('Response status:', response.statusCode); }); // Registered method client.registerMethod('getPost', 'https://jsonplaceholder.typicode.com/posts/${id}', 'GET'); const args = { path: { id: 2 }, headers: { 'Accept': 'application/json' } }; client.methods.getPost(args, function(data, response) { console.log('Registered method data:', data); }); // POST example const postArgs = { data: { title: 'foo', body: 'bar', userId: 1 }, headers: { 'Content-Type': 'application/json' } }; client.post('https://jsonplaceholder.typicode.com/posts', postArgs, function(data, response) { console.log('POST response:', data); });
Debug
Known issues
gotchaPOST, PUT, PATCH requests require 'Content-Type' header in args, otherwise they may fail or behave unexpectedly.
fix
Always set 'Content-Type' header (e.g., 'application/json') in the headers argument for methods that send a body.
affects: >=1.0.0
gotchaWhen using registered methods, path parameters like ${id} must be provided in args.path, but the URL string must use '${}' syntax, not ':'.
fix
Use template literal-style placeholders in URL: 'http://example.com/resource/${id}' and pass { path: { id: value } }.
affects: >=3.0.0
gotchaThe callback receives response as second argument, not first. Many users expect (response, data) order.
fix
Use function(data, response) { ... } with data first, response second.
affects: >=1.0.0
deprecatedThe option 'followRedirects' is deprecated; redirects are now always followed using the follow-redirects package.
fix
Remove followRedirects option; redirect handling is automatic.
affects: >=4.0.0
gotchaDefault serializer for request data is 'application/x-www-form-urlencoded' when Content-Type is not set, even for POST with JSON objects.
fix
Explicitly set headers: { 'Content-Type': 'application/json' } when sending JSON payloads.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: client.get is not a function
Importing the package as default export instead of destructuring { Client }.
fix
Use const { Client } = require('node-rest-client');
Error: Cannot find module 'follow-redirects'
Missing dependency when using npm versions that don't auto-install peer deps.
fix
Run npm install node-rest-client --save, which will install follow-redirects as a dependency.
The request body is empty or not sent
Missing or incorrect Content-Type header for POST/PUT/PATCH requests.
fix
Add headers: { 'Content-Type': 'application/json' } to the args object.
Cannot read property 'get' of undefined
Accessing client.methods before registering any method or using unregistered method name.
fix
Call client.registerMethod(name, url, verb) before accessing client.methods.name.
Upgrade
Version history
4.0.0latest on npm
Audit
Dependencies
follow-redirectsrequiredHandles HTTP redirects transparently
xml2jsoptionalProvides XML response parsing when content-type is XML
Agent activity
4 hits · last 30 days
node
4
Resources
node-rest-api-client — npm install node-rest-api-client · libregistry