Registry / http-networking / request-json

request-json

JSON →
library0.6.5jsnpmunverified

request-json is a Node.js HTTP client specifically designed to streamline interactions with JSON APIs. It acts as a wrapper around the now-deprecated `request` library, simplifying common tasks like sending and receiving JSON payloads, handling basic authentication, and uploading/downloading files. Currently at version 0.6.5, the package has seen no updates for several years, effectively rendering it unmaintained. Its core differentiator was abstracting away some complexities of the underlying `request` library, offering a more fluent API for JSON-centric operations and basic promise support via `.then()`. Due to its fundamental dependency on the unmaintained `request` package, `request-json` should be considered unstable and potentially insecure for new projects, with no ongoing release cadence.

npm install request-json
INSTALL
IMPORT
SIG · REQUEST-JSON
R
request-json
http-networkingjavascriptv0.6.5
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

request
const request = require('request-json');
import request from 'request-json'
This package is CommonJS-only and does not provide ES module exports. Direct import of the module is usually followed by calling `createClient()`.
createClient
const client = request.createClient('http://localhost:8888/');
const client = new request.newClient('http://localhost:8888/');
The `newClient()` method is deprecated in favor of `createClient()` and will emit a warning, although it remains functional.
post
client.post('posts/', data, (err, res, body) => { /* ... */ });
Most client methods (`get`, `post`, `put`, `del`, `patch`, `sendFile`, `saveFile`) primarily accept a callback, but also return a Promise for `.then().catch()` usage.

This quickstart demonstrates how to initialize the request-json client and perform various HTTP methods (POST, GET, PUT, DELETE, PATCH) to a mock API endpoint, including basic authentication and custom headers. It showcases both callback-based and promise-based approaches.

const request = require('request-json'); const client = request.createClient('http://localhost:8888/'); console.log('--- Simulating API calls to http://localhost:8888/ ---'); // POST request const postData = { title: 'my title', content: 'my content' }; client.post('posts/', postData, function(err, res, body) { if (err) return console.error('POST Error:', err); console.log(`POST /posts/ Status: ${res.statusCode}`); // console.log('POST Body:', body); // In a real scenario, body would contain the API's response }); // GET request client.get('posts/', function(err, res, body) { if (err) return console.error('GET Error:', err); console.log(`GET /posts/ Status: ${res.statusCode}`); // console.log('GET Body (first title):', body?.rows?.[0]?.title); // Assuming a structure, this would be undefined without a real server }); // PUT request const putData = { title: 'my new title' }; client.put('posts/123/', putData, function(err, res, body) { if (err) return console.error('PUT Error:', err); console.log(`PUT /posts/123/ Status: ${res.statusCode}`); }); // DELETE request client.del('posts/123/', function(err, res, body) { if (err) return console.error('DEL Error:', err); console.log(`DEL /posts/123/ Status: ${res.statusCode}`); }); // PATCH request with Promises const patchData = { title: 'my patched title' }; client.patch('posts/123/', patchData) .then(function(result) { console.log(`PATCH /posts/123/ Status: ${result.res.statusCode}`); // console.log('PATCH Body:', result.body); }) .catch(err => { console.error('PATCH Error:', err); }); // Basic Authentication example client.setBasicAuth('john', 'secret'); client.get('private/posts/', function(err, res, body) { if (err) return console.error('Auth GET Error:', err); console.log(`Authenticated GET /private/posts/ Status: ${res.statusCode}`); }); // Headers manipulation client.headers['X-Custom-Header'] = 'MyValue'; console.log('Client configured with X-Custom-Header.');
Debug
Known issues
breakingThe underlying `request` library, which `request-json` relies on, was fully deprecated on February 11, 2020. This means `request-json` is built on an unmaintained and potentially insecure foundation, lacking future updates, bug fixes, or security patches.
fix
Migrate to a modern, actively maintained HTTP client like `axios`, `node-fetch`, or `undici`. If migrating from `request`, consider `got` as a direct successor.
affects: >=0.0.1
deprecatedThe `newClient()` method is deprecated. While still functional, it will emit a deprecation warning.
fix
Always use `request.createClient()` instead of `new request.newClient()`.
affects: <=0.6.5
gotchaError handling typically relies on Node.js-style callbacks (`(err, res, body) => {}`) where the first argument is an error. For promise-based calls, `.catch()` should be used.
fix
Ensure both `err` argument in callbacks and `.catch()` blocks for promises are implemented to handle network or API errors gracefully.
affects: <=0.6.5
gotchaThe package uses CommonJS `require()` syntax exclusively. It does not provide native ES module exports, which is the standard for modern JavaScript projects.
fix
Continue using `require('request-json')` in CommonJS environments. For ES module environments, a wrapper or re-bundling might be necessary, or ideally, migrate to a native ESM-compatible HTTP client.
affects: <=0.6.5
gotchaFile upload methods (`sendFile`) have specific key naming conventions (`'file'` for single files, `'file0', 'file1', ...` for arrays) which might not align with all API expectations, requiring server-side adaptation or careful client-side data preparation.
fix
Verify the expected key names for file uploads on your target API and adapt the `request-json` usage or implement custom file handling if necessary.
affects: <=0.6.5
Errors
Common errors & fixes
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
This warning appears because `request-json` depends on the `request` package, which is no longer maintained.
fix
While this specific warning cannot be 'fixed' within `request-json` without updating its core dependency, it signals an urgent need to migrate away from `request-json` to a modern HTTP client library for security and stability reasons.
TypeError: request.createClient is not a function
Attempting to use `new` keyword with `createClient()` or calling `createClient` before requiring `request-json`.
fix
Ensure `const request = require('request-json');` is correctly placed and `createClient()` is called directly on the imported `request` object: `const client = request.createClient('http://localhost:8888/');`.
UnhandledPromiseRejectionWarning: Unhandled promise rejection.
A promise-returning method (e.g., `client.get().then(...)`) encountered an error, but no `.catch()` handler was provided.
fix
Always chain a `.catch(err => { console.error(err); })` to any promise-returning `request-json` method to handle potential errors.
Upgrade
Version history
0.6.5latest on npm
Audit
Dependencies
requestrequiredCore HTTP client library; deprecated on February 11, 2020, and no longer maintained. This critically impacts request-json's viability and security.
Agent activity
8 hits · last 30 days
node
8
Resources
request-json — npm install request-json · libregistry