Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

react-resource

cidevant399MIT2.0.9

A factory which creates a resource object that lets you interact with RESTful server-side data sources.

React, Resource, ngResource, REST, RESTful, RESTful Api, Promise, Api

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

changelog

2.0.9

  • updated docs

2.0.8

  • fix: Action promise does not call catch when there's an interceptor

2.0.7

  • handle non JSON responses

2.0.6

  • Fixed instatiation of Model data

2.0.5

  • Fixed typo

2.0.4

  • Fixed build

2.0.0

  • Rewrited 100% of code
  • Exposed global whatwg-fetch config (fetchOptions)
  • Send files
  • Make instances from action response data
  • transformRequest and transformResponse in action config
  • Webpack dev server

1.0.9

  • Prevent import of the whole lodash library

1.0.8

  • Added Interceptors