Registry / http-networking / restler-base

restler-base

JSON →
library3.4.6jsnpmunverified

restler-base is a fork of the unmaintained restler HTTP client library for Node.js, version 3.4.6. It incorporates pending pull requests and fixes from the original project, serving as the foundation for restler-promise. The library provides an event-based API for making HTTP requests with automatic serialization of post data and query strings, transparent handling of SSL, redirects, gzip/deflate, and basic auth, plus automatic deserialization of XML, JSON, and YAML responses. It supports multipart file uploads and custom deserializers. Compared to modern alternatives like axios or node-fetch, restler-base is older and uses an event-driven pattern rather than promises, though it can be wrapped with restler-promise. Release cadence is low; last release was 3.4.6. Key differentiator: it is a maintained fork of restler, preserving its specific API for legacy projects.

npm install restler-base
INSTALL
IMPORT
SIG · RESTLER-BASE
R
restler-base
http-networkingjavascriptv3.4.6
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.

restler
✓ import restler from 'restler-base'
✗ const restler = require('restler-base')
ESM works, but restler-base uses CommonJS internally. Default import works in both ESM and CJS.
request
✓ import { request } from 'restler-base'
✗ import { request } from 'restler'
Do not import from 'restler' as that is the unmaintained original. Use 'restler-base'.
get
✓ import { get, post, put, del } from 'restler-base'
✗ import get from 'restler-base/get'
All methods (get, post, put, del) are named exports from the main package, not subpath exports.

Demonstrates basic HTTP GET and POST using the event-based API with error handling via 'complete' and 'success'/'fail' events.

import restler from 'restler-base'; restler.get('https://api.example.com/data', { headers: { 'Accept': 'application/json' }, timeout: 5000 }).on('complete', (result, response) => { if (result instanceof Error) { console.error('Error:', result.message); } else { console.log('Data:', result); } }); restler.post('https://api.example.com/submit', { data: { name: 'test', value: 123 }, headers: { 'Content-Type': 'application/json' } }).on('success', (data, response) => { console.log('Posted successfully:', data); }).on('fail', (data, response) => { console.error('Failed with status:', response.statusCode); });
Debug
Known issues
gotchaThe 'complete' event fires even on errors, and the first argument is an Error instance on failure. Always check if result instanceof Error.
fix
Always check 'result instanceof Error' in 'complete' event handler before using result.
affects: >=0.0.0
deprecatedLibrary uses a callback/event-driven pattern; newer projects should consider axios or node-fetch with promise support.
fix
Consider using the restler-promise wrapper for promise-based API, or migrate to axios.
affects: >=3.0.0
gotchaAutomatic XML/YAML deserialization requires optional dependencies (xml2js, yamljs). Without them, responses will be strings.
fix
Install optional dependencies: npm install xml2js yamljs
affects: >=0.0.0
gotchaThe 'timeout' option is in milliseconds; if not set, requests may hang indefinitely.
fix
Always set timeout option to a reasonable value (e.g., 10000).
affects: >=0.0.0
gotchaWhen using 'multipart: true', you must provide a 'data' object containing file properties with 'file' and 'name' sub-fields.
fix
Format multipart data as { file: { file: '/path/to/file', name: 'fieldname' } }.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'restler-base'
Package not installed or imported from wrong package name.
fix
Run 'npm install restler-base' and ensure import is from 'restler-base' not 'restler'.
TypeError: Cannot read property 'on' of undefined
Forgetting to call a method like get() or post() returns a request object, but if URL is invalid or options cause immediate error, may return undefined.
fix
Check URL and options, ensure function returns a RestRequest object before chaining .on()
Error: connect ECONNREFUSED 127.0.0.1:80
No server listening on the target host/port (e.g., localhost test server not started).
fix
Ensure target server is running, or use a valid URL.
Warning: Possible EventEmitter memory leak detected. 11 complete listeners added.
Adding many listeners on the same request object without removing or using once.
fix
Use .once() instead of .on() if listeners should fire only once, or manage listener removal with .removeListener().
Upgrade
Version history
3.4.6latest on npm
Audit
Dependencies
iconv-liteoptionalAutomatic charset decoding for responses
xml2jsoptionalXML response deserialization
yamljsoptionalYAML response deserialization
Agent activity
2 hits · last 30 days
node
2
Resources
restler-base — npm install restler-base · libregistry