restler-base
raw JSON →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.
Common errors
error Cannot find module 'restler-base' ↓
error TypeError: Cannot read property 'on' of undefined ↓
error Error: connect ECONNREFUSED 127.0.0.1:80 ↓
error Warning: Possible EventEmitter memory leak detected. 11 complete listeners added. ↓
Warnings
gotcha The 'complete' event fires even on errors, and the first argument is an Error instance on failure. Always check if result instanceof Error. ↓
deprecated Library uses a callback/event-driven pattern; newer projects should consider axios or node-fetch with promise support. ↓
gotcha Automatic XML/YAML deserialization requires optional dependencies (xml2js, yamljs). Without them, responses will be strings. ↓
gotcha The 'timeout' option is in milliseconds; if not set, requests may hang indefinitely. ↓
gotcha When using 'multipart: true', you must provide a 'data' object containing file properties with 'file' and 'name' sub-fields. ↓
Install
npm install restler-base yarn add restler-base pnpm add restler-base Imports
- restler wrong
const restler = require('restler-base')correctimport restler from 'restler-base' - request wrong
import { request } from 'restler'correctimport { request } from 'restler-base' - get wrong
import get from 'restler-base/get'correctimport { get, post, put, del } from 'restler-base'
Quickstart
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);
});