2.0.9 • Published 2 years ago

react-resource v2.0.9

Weekly downloads
26
License
MIT
Repository
github
Last release
2 years ago

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 --save

Documentation

  1. Model class
  2. Actions
  3. Interceptors
  4. Transformers
  5. File upload

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());
});
2.0.9

2 years ago

2.0.8

2 years ago

2.0.7

7 years ago

2.0.6

8 years ago

2.0.5

8 years ago

2.0.4

8 years ago

2.0.3

8 years ago

2.0.2

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.0.9

8 years ago

1.0.8

9 years ago

1.0.7

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago