Registry / storage / consumerjs

consumerjs

JSON →
library3.2.1jsnpmunverified

ConsumerJS is a JavaScript library that provides an ORM-like repository/entity mapper for consuming RESTful JSON APIs, built on top of Axios. The current stable version is 3.2.1. It supports CRUD operations, Django CSRF protection, and can be extended with custom behavior. Unlike raw Axios or fetch, it offers a declarative, object-oriented approach with stateful entity objects and consumer classes that map API endpoints to JavaScript classes. It uses an active release cadence with breaking changes in major versions.

npm install consumerjs
INSTALL
IMPORT
SIG · CONSUMERJS
C
consumerjs
storagejavascriptv3.2.1
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.

CrudConsumer
✓ import { CrudConsumer } from 'consumerjs'
✗ import CrudConsumer from 'consumerjs'
Named export, not default.
CrudConsumerObject
✓ import { CrudConsumerObject } from 'consumerjs'
✗ import CrudConsumerObject from 'consumerjs'
Named export, not default.
Consumer
✓ import { Consumer } from 'consumerjs'
✗ const Consumer = require('consumerjs').Consumer
ESM-only since v3; CJS is not supported.
ConsumerObject
✓ import { ConsumerObject } from 'consumerjs'
✗ import ConsumerObject from 'consumerjs'
Named export, not default.

Shows how to define a CrudConsumer and CrudConsumerObject for a Post resource, then create and read/update instances.

import { CrudConsumer, CrudConsumerObject } from 'consumerjs'; class Post extends CrudConsumerObject {} class PostConsumer extends CrudConsumer { constructor(endpoint = 'https://api.example.com/posts/', objectClass = Post) { super(endpoint, objectClass); } } const postConsumer = new PostConsumer(); postConsumer.create() .then(post => console.log('Created:', post)) .catch(err => console.error(err)); postConsumer.read(1) .then(post => { post.title = 'updated title'; post.update(); });
Debug
Known issues
breakingDropped CommonJS (CJS) support; package is ESM-only since v3.
fix
Use import statements only; avoid require().
affects: >=3.0.0
breakingRequires @babel/polyfill for older browsers (IE11) as of v2.0.0.
fix
Install @babel/polyfill and import it in your entry point.
affects: >=2.0.0
deprecatedOld import paths from v1 (e.g., 'consumerjs/lib/...') are removed; use main entry 'consumerjs'.
fix
Import from 'consumerjs' directly.
affects: >=2.0.0
gotchaAxios is a peer dependency; must be installed separately.
fix
Run 'npm install axios' alongside consumerjs.
affects: >=1.0.0
gotchaConsumer objects resolve 'id' from either 'id' or 'pk' field by default; both fields in response may cause unexpected behavior.
fix
Ensure API response includes either 'id' or 'pk', not conflicting values.
affects: >=1.0.0
deprecatedNo TypeScript type definitions bundled; community may provide them.
fix
Check @types/consumerjs or use typed wrappers.
affects: <=3.2.1
Errors
Common errors & fixes
Cannot find module 'consumerjs'
Package not installed or import path incorrect.
fix
Run 'npm install consumerjs' and use 'import { ... } from 'consumerjs''.
Cannot read property 'create' of undefined
Default import used instead of named import for CrudConsumer.
fix
Use 'import { CrudConsumer } from 'consumerjs'' (named import).
Module not found: Can't resolve 'axios'
Peer dependency axios not installed.
fix
Run 'npm install axios'.
Unexpected token 'export' (or 'import')
Using CommonJS require() with ESM-only package v3+.
fix
Switch to import syntax or use dynamic import().
Upgrade
Version history
3.2.1latest on npm
Audit
Dependencies
axiosrequiredHTTP client for making REST requests
@babel/polyfilloptionalRequired for older browser support (IE11) as of v2.0.0
Agent activity
27 hits · last 30 days
node
24
Resources
consumerjs — npm install consumerjs · libregistry