![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
consumerjs
Advanced tools
ConsumerJS is a REST client/object mapper that aims to make using RESTful JSON API's simple and DRY.
ConsumerJS is a REST client/object mapper that aims to make using RESTful JSON API's simple and DRY. It converts JSON responses to objects allowing CRUD operations on remote resources. ConsumerJS automatically adds a CSRF header (if the CSRF cookie is present).
Install with npm.
$ npm i consumerjs --save
This library can be used in the browser only. See doc for full API documentation.
Example:
data/post.js
import { CrudConsumer, CrudConsumerObject } from 'consumerjs';
class Post extends CrudConsumerObject {}
class PostConsumer extends CrudConsumer {
constructor(endpoint='http://example.com/api/v1/posts/', objectClass=Post) {
super(endpoint, objectClass);
}
;}
export default PostConsumer;
examples/my-app.js
import PostConsumer from '../data/post.js';
let postConsumer = new PostConsumer();
postConsumer.create()
.then(someFunction) // When promise resolves, call someFunction with new Post object
.catch(errorFunction); // When promise rejects, call errorFunction
//
// When a consumer receives a JSON array as result, an array of consumer objects is returned.
//
postConsumer.read()
.then(someFunction) // When promise resolves, call someFunction with all resolved Post objects
.catch(errorFunction); // When promise rejects, call errorFunction
let id = 1;
postConsumer.read(id)
.then(someFunction) // When promise resolves, call someFunction with resolved Post (with id 1)
.catch(errorFunction); // When promise rejects, call errorFunction
examples/my-app2.js
// Internally, id is resolved using either "pk" or "id" field
post.title = 'some new title';
post.update() // Saves changed fields to API using partial PATCH request
post.save() // Save all fields to API using full PUT request
post.delete() // Deletes this post using DELETE request
ConsumerJS defines a few built-in classes, all of those should be extended by a custom class:
Consumers (Consumer, CrudConsumer):
"Consumers" are classes that define how to perform operations on the remote API. It converts the results to "Consumer object" which contains a statefull representation of the API result.
A consumer:
Consumers should be extended, configured and optionally methods can be overwritten to change default behaviour. Configuration should be done in de constructor method:
/**
* Configures Consumer instance
* @param {string} endpoint Base endpoint for this API
* @param {AbstractConsumerObject} objectClass Class to cast results to
* @param {Object} [options] Additional configuration
*/
constructor(endpoint='http://example.com/api/v1/posts/', objectClass=Post, options=null) {
super(endpoint, objectClass);
}
create([object])
, creates objecs.read([id])
, fetches all objects or a single object by id.Consumer objects (ConsumerObject, CrudConsumerObject):
"Consumer objects" are classes that define how to perform object specific operations on the remote API. Consumer objects should be extended, configured and optionally methods can be overwritten to change default behaviour.
A consumer object:
A reference to the consumer is kept using the __consumer__ property, (custom) methods can use this to communicate with the API.
customMethod(data) {
return this.__consumer.__.post('/path/', data); // CrudConsumerObject instances can use this.getPath() as path.
}
update()
, persists changes made to object.save()
, fully saves object.delete()
, deletes this object.FAQs
Consumerjs simplifies REST with an ORM like approach. Built on top of Axios.
We found that consumerjs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.