Node.js REST Client

3.1.1 · active · verified Sun Apr 19

node-rest-client is a versatile Node.js library for interacting with RESTful APIs, designed to simplify HTTP/HTTPS requests. It offers features such as transparent handling of HTTP/HTTPS connections, basic authentication, and support for common HTTP methods (GET, POST, PUT, DELETE, PATCH), with the ability to define custom methods. A key differentiator is its capability to register remote API operations as reusable client methods, streamlining code and promoting reuse. The library also manages dynamic path and query parameters, request headers, provides improved error handling, supports compressed responses (gzip, deflate), follows redirects (via `follow-redirects`), and allows for custom request serializers and response parsers (with JSON and XML included by default). The current stable version is 3.1.1. Release cadence is not strictly scheduled, but the project shows active development with recent major and minor updates.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to install `node-rest-client` and perform both a simple HTTP GET request and an HTTP POST request with JSON data and headers to a public API.

const Client = require('node-rest-client').Client;

const client = new Client();

// Example: Simple HTTP GET request
client.get("https://jsonplaceholder.typicode.com/posts/1", function (data, response) {
	// parsed response body as js object
	console.log('GET Response Data:', data);
	// raw response
	console.log('GET Response Status:', response.statusCode);
});

// Example: HTTP POST request with JSON data and headers
const args = {
	data: { title: 'foo', body: 'bar', userId: 1 },
	headers: { "Content-Type": "application/json" }
};

client.post("https://jsonplaceholder.typicode.com/posts", args, function (data, response) {
	console.log('POST Response Data:', data);
	console.log('POST Response Status:', response.statusCode);
});

view raw JSON →