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.
npm install node-rest-clientVerified import paths — ran on the pinned version, not inferred.
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.
Review your code for any direct calls to non-public `node-rest-client` methods. If such calls exist, either refactor to use documented public APIs or adjust to the new `$` prefixed names, noting this is an internal implementation detail and subject to change.
Always include `headers: { 'Content-Type': 'application/json' }` (or appropriate type) in the `args` object for methods sending a request body (POST, PUT, PATCH).If your API returns non-standard content types or requires specific parsing, add custom parsers to the client configuration. For example, `new Client({ mimetypes: { json: ['application/json', 'application/json;charset=utf-8'] } })` to explicitly define how content types are handled.Ensure the second argument to `client.post`, `client.put`, or `client.patch` is always an `args` object, even if empty, before the callback function.
Verify the `Content-Type` header sent by the API. If it's a custom type or not correctly handled, configure custom response parsers using `client.registerParser()` or `new Client({ mimetypes: { /* ... */ } })`.For ESM projects, use dynamic `import('node-rest-client')` and then access the `Client` class, e.g., `const { Client } = await import('node-rest-client');`. Alternatively, ensure your file is treated as CommonJS (e.g., `.cjs` extension or no `"type": "module"` in `package.json`).