rest.js is an HTTP client library designed for both browser and Node.js environments, emphasizing extensibility through its interceptor-based architecture. It provides core functionality for making HTTP requests and normalizing request/response objects, with advanced features like MIME type conversion, error handling, and hypermedia API traversal implemented as composable interceptors. The current stable version is 2.0.0, which notably moved from a hard dependency on `when.js` to native ES6 Promises and completely dropped AMD module support. Releases historically occurred somewhat frequently for major feature additions in 1.x, with 2.0.0 being a significant breaking change. It allows developers to configure tailored HTTP clients by wrapping a basic client with only the necessary features, promoting a lightweight and modular approach to client-side HTTP interactions, differentiating it from monolithic HTTP libraries.
npm install restVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create an advanced `rest.js` client by composing multiple interceptors, including `pathPrefix` for base URL, `defaultRequest` for adding common headers, `mime` for automatic JSON parsing, and `errorCode` for robust error handling. It shows both GET and POST requests, using `process.env` for API key management.
Ensure your environment supports native ES6 Promises, or include a polyfill like `when.js`'s ES6 shim before loading rest.js. Update promise handling logic to conform to ES6 Promise standards.
Migrate to CommonJS (Node.js) or bundle for browser environments using tools like Browserify or Webpack. For curl.js users, the `cjsm11` loader might offer a workaround.
Manually apply parameter replacement before making requests, or consider using other interceptors/utilities for URI templating if needed. The `params` interceptor can still be used but is considered deprecated.
Remove the `rest/interceptor/entity` interceptor from your client chain and access the parsed entity directly using `response.entity()` after a request completes.
Replace all calls to `client.chain()` with `client.wrap()` when configuring interceptors.
Update your import paths in browser-side code from `require('rest/rest')` to `require('rest/browser')`.Ensure that a global ES6 `Promise` object is available. If targeting older environments, include a `Promise` polyfill (e.g., from `when.js` or `core-js`) before `rest.js` is loaded.
For Node.js ESM projects, ensure compatibility layer or use dynamic `import('rest')`. For browser, use a bundler like Webpack/Rollup that handles CJS modules. Or, switch your file to CommonJS if possible.Remove the import for `rest/interceptor/entity` and discontinue its use. Access the parsed response entity directly via `response.entity()` instead.
Update all instances of `client.chain()` to `client.wrap()` which is the preferred method for interceptor composition.
No dependency data recorded yet.