Package Exports
- react-resource
- react-resource/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-resource) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
React Resource
A factory which creates a resource object (Model class) that lets you interact with RESTful server-side data sources.
The returned resource object (Model class) has action methods which provide high-level behaviors without the need to interact with the low level http service (whatwg-fetch).
Install
npm install react-resource --saveDocumentation
Example
import ReactResource from 'react-resource';
// Model class definition
const User = new ReactResource('/api/users/{:id}.json', { id: ':id' })
// Custom instance method
User.prototype.getName = function() {
return [this.first_name, this.last_name].join(" ");
};
// Action `create` as class method
User.create({first_name: 'John', last_name: 'Doe'}, (user) => {
console.log('[CLASS]', user.getName());
});
// Action `create` as instance method
const user = new User({first_name: 'Johnny', last_name: 'Bravo'});
const promise = user.$create((user) => {
console.log('[INSTANCE]', user.getName());
});