{"id":26315,"library":"restler-base","title":"restler-base","description":"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.","status":"maintenance","version":"3.4.6","language":"javascript","source_language":"en","source_url":"https://github.com/mwittig/restler-base","tags":["javascript"],"install":[{"cmd":"npm install restler-base","lang":"bash","label":"npm"},{"cmd":"yarn add restler-base","lang":"bash","label":"yarn"},{"cmd":"pnpm add restler-base","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Automatic charset decoding for responses","package":"iconv-lite","optional":true},{"reason":"XML response deserialization","package":"xml2js","optional":true},{"reason":"YAML response deserialization","package":"yamljs","optional":true}],"imports":[{"note":"ESM works, but restler-base uses CommonJS internally. Default import works in both ESM and CJS.","wrong":"const restler = require('restler-base')","symbol":"restler","correct":"import restler from 'restler-base'"},{"note":"Do not import from 'restler' as that is the unmaintained original. Use 'restler-base'.","wrong":"import { request } from 'restler'","symbol":"request","correct":"import { request } from 'restler-base'"},{"note":"All methods (get, post, put, del) are named exports from the main package, not subpath exports.","wrong":"import get from 'restler-base/get'","symbol":"get","correct":"import { get, post, put, del } from 'restler-base'"}],"quickstart":{"code":"import restler from 'restler-base';\n\nrestler.get('https://api.example.com/data', {\n  headers: { 'Accept': 'application/json' },\n  timeout: 5000\n}).on('complete', (result, response) => {\n  if (result instanceof Error) {\n    console.error('Error:', result.message);\n  } else {\n    console.log('Data:', result);\n  }\n});\n\nrestler.post('https://api.example.com/submit', {\n  data: { name: 'test', value: 123 },\n  headers: { 'Content-Type': 'application/json' }\n}).on('success', (data, response) => {\n  console.log('Posted successfully:', data);\n}).on('fail', (data, response) => {\n  console.error('Failed with status:', response.statusCode);\n});","lang":"typescript","description":"Demonstrates basic HTTP GET and POST using the event-based API with error handling via 'complete' and 'success'/'fail' events."},"warnings":[{"fix":"Always check 'result instanceof Error' in 'complete' event handler before using result.","message":"The 'complete' event fires even on errors, and the first argument is an Error instance on failure. Always check if result instanceof Error.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Consider using the restler-promise wrapper for promise-based API, or migrate to axios.","message":"Library uses a callback/event-driven pattern; newer projects should consider axios or node-fetch with promise support.","severity":"deprecated","affected_versions":">=3.0.0"},{"fix":"Install optional dependencies: npm install xml2js yamljs","message":"Automatic XML/YAML deserialization requires optional dependencies (xml2js, yamljs). Without them, responses will be strings.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Always set timeout option to a reasonable value (e.g., 10000).","message":"The 'timeout' option is in milliseconds; if not set, requests may hang indefinitely.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Format multipart data as { file: { file: '/path/to/file', name: 'fieldname' } }.","message":"When using 'multipart: true', you must provide a 'data' object containing file properties with 'file' and 'name' sub-fields.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run 'npm install restler-base' and ensure import is from 'restler-base' not 'restler'.","cause":"Package not installed or imported from wrong package name.","error":"Cannot find module 'restler-base'"},{"fix":"Check URL and options, ensure function returns a RestRequest object before chaining .on()","cause":"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.","error":"TypeError: Cannot read property 'on' of undefined"},{"fix":"Ensure target server is running, or use a valid URL.","cause":"No server listening on the target host/port (e.g., localhost test server not started).","error":"Error: connect ECONNREFUSED 127.0.0.1:80"},{"fix":"Use .once() instead of .on() if listeners should fire only once, or manage listener removal with .removeListener().","cause":"Adding many listeners on the same request object without removing or using once.","error":"Warning: Possible EventEmitter memory leak detected. 11 complete listeners added."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}