Registry / devops / sync-rest-client

sync-rest-client

JSON →
library1.0.3jsnpmunverified

sync-rest-client is a synchronous, non-blocking REST/HTTP client for Node.js built on deasync and request. Version 1.0.3 uses deasync to wrap request, enabling synchronous HTTP calls without blocking the event loop. It supports retries (default 3), timeouts, and graceful error handling. Key differentiator: it avoids thread-blocking issues seen with other sync libraries like sync-request when used alongside async code. Last updated 2018, low maintenance. Use cases: scripts, CLI tools, or scenarios requiring synchronous HTTP operations without event loop blockage.

npm install sync-rest-client
INSTALL
IMPORT
SIG · SYNC-REST-CLIENT
S
sync-rest-client
devopsjavascriptv1.0.3
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.

default
const syncClient = require('sync-rest-client');
const syncClient = require('sync-rest-client').default;
CommonJS only; no ESM or named exports. Use require for import.
.get
syncClient.get('https://example.com');
syncClient.get('https://example.com', {});
Options object is optional. No callback; synchronous return.
.setGlobalRetry
syncClient.setGlobalRetry(5);
Sets retry count globally for all requests. Default is 3.

Demonstrates GET request with options (timeout and retries) and handling the synchronous response object.

const syncClient = require('sync-rest-client'); const response = syncClient.get('https://api.github.com/users/ujc', { timeout: 5, // seconds retries: 2 }); if (response.statusCode === 200) { console.log('Body:', response.body); console.log('Retries used:', response.retriesCount); } else { console.error('Error:', response.code || response.statusCode); }
Debug
Known issues
breakingUnderlying request module is deprecated; deasync may cause event loop issues in some environments.
fix
Consider migrating to async alternatives or use newer sync libraries like sync-fetch.
affects: >=1.0.0
gotchadelete verb is named 'del', not 'delete'. Using syncClient.delete() will throw an error.
fix
Use syncClient.del(url, options) for DELETE requests.
affects: >=1.0.0
gotchaResponse.body is automatically parsed from JSON; if body is not JSON, it returns a string.
fix
Check typeof response.body before assuming it's an object.
affects: >=1.0.0
deprecatedPackage uses deprecated request library as of 2020. Unmaintained since 2018.
fix
Use alternatives like sync-fetch or got (async) for new projects.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: syncClient.get is not a function
Incorrect default import (e.g., import defaults) or wrong module path.
fix
Use const syncClient = require('sync-rest-client'); in CommonJS.
RequestError: ESOCKETTIMEDOUT
Server did not respond within timeout seconds.
fix
Increase timeout in options or check network/server availability.
Error: retries is not a number
Passed non-integer or string for retries in options.
fix
Ensure retries property is a positive integer (e.g., retries: 2).
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies
deasyncrequiredrequired for synchronous non-blocking behavior
requestrequiredunderlying HTTP client
Agent activity
5 hits · last 30 days
node
4
Amazon
1
Resources
sync-rest-client — npm install sync-rest-client · libregistry