Registry / devops / rest-js

rest-js

JSON →
library1.1.3jsnpmunverified

A lightweight REST client that works in both browser and Node.js environments, with CRUD methods, promise support, caching, and a middleware system for request/response transformation. Version 1.1.3 is the latest stable release, with low maintenance cadence. Differentiators include isomorphic design (client/server), URL-based response caching, and built-in middlewares for JSON handling and HTTP method workaround for browsers. Supports GET, POST, PUT, DELETE and arbitrary HTTP methods via .request().

npm install rest-js
INSTALL
IMPORT
SIG · REST-JS
R
rest-js
devopsjavascriptv1.1.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.

rest
import rest from 'rest-js'
const { rest } = require('rest-js')
Default export; named import { rest } is incorrect. Use default import or const rest = require('rest-js').
rest instance methods
const api = rest('baseUrl', options); api.read('/path', callback);
rest.read('/path')
.read() is an instance method, not a static method. Must create an instance first.
middleware .use()
api.use(function(request, next) { next(); })
api.use(function(request, response, next) { next(); })
Middleware arity matters: 2 params = request filter, 3 params = request+response filter, 4 params = error filter. Wrong number of params will cause runtime errors.

Create a REST client instance, issue a GET request, and handle the response using both callback and promise patterns.

const rest = require('rest-js'); const api = rest('https://jsonplaceholder.typicode.com', { crossDomain: false, cacheLifetime: 0 }); api.read('posts/1', (error, data) => { if (error) console.error(error); else console.log(data); }); // Promise also works: api.read('posts').then(data => console.log(data)).catch(err => console.error(err));
Debug
Known issues
gotchaMiddleware arity matters: passing wrong number of parameters to .use() can cause unexpected behavior.
fix
Ensure middleware function has exactly the number of parameters expected: 2 for request filter, 3 for request+response, 4 for error filter.
affects: >=1.0.0
deprecatedThe 'del' alias for 'remove' may be confusing; prefer 'remove' for clarity.
fix
Use .remove() instead of .del() as it's more descriptive.
affects: >=1.0.0
gotchaCaching is enabled by default with cacheLifetime: 5000. GET requests are cached, which may cause stale data.
fix
Set cacheLifetime: 0 to disable caching, or adjust the lifetime as needed.
affects: >=1.0.0
breakingThe package does not support named exports; only default export is available.
fix
Use default import: import rest from 'rest-js' or const rest = require('rest-js').
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: rest.read is not a function
Trying to call .read() as a static method on the imported default function.
fix
Create an instance first: const api = rest(baseUrl); api.read(path);
TypeError: api.use is not a function
Using .use() before creating an instance, or using a non-function argument.
fix
Ensure you have created an instance: const api = rest(baseUrl); api.use(middleware);
Error: Cannot find module 'rest-js'
Package not installed or wrong import path.
fix
Run 'npm install rest-js' and use 'const rest = require("rest-js")'.
Upgrade
Version history
1.1.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Amazon
1
Resources
rest-js — npm install rest-js · libregistry